Get date from input form within PHP

前端 未结 2 1560
借酒劲吻你
借酒劲吻你 2020-12-13 21:09

I\'m trying to retrieve a date from a date input form and I just can\'t get it to work properly. The code I\'m using now only returns an error and this date: 1970-01-01. Tha

2条回答
  •  失恋的感觉
    2020-12-13 21:42

    Validate the INPUT.

    $time = strtotime($_POST['dateFrom']);
    if ($time) {
      $new_date = date('Y-m-d', $time);
      echo $new_date;
    } else {
       echo 'Invalid Date: ' . $_POST['dateFrom'];
      // fix it.
    }
    

提交回复
热议问题