Get date from input form within PHP

前端 未结 2 1561
借酒劲吻你
借酒劲吻你 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.
    }
    
    0 讨论(0)
  • 2020-12-13 21:49
        <?php
    if (isset($_POST['birthdate'])) {
        $timestamp = strtotime($_POST['birthdate']); 
        $date=date('d',$timestamp);
        $month=date('m',$timestamp);
        $year=date('Y',$timestamp);
    }
    ?>  
    
    0 讨论(0)
提交回复
热议问题