html - Get date from input form within PHP -


i'm trying retrieve date date input form , can't work properly. code i'm using returns error , date: 1970-01-01. not correct , know how can approach this. used later query database table. want date string format: "yyyy-mm-dd"

code:

html

<form name="datefilter" method="post"> from: <input type="date" name="datefrom" value="<?php echo date('y-m-d'); ?>" /> <br/> to: <input type="date" name="dateto" value="<?php echo date('y-m-d'); ?>" /> </form> 

php

$new_date = date('y-m-d', strtotime($_post['datefrom'])); echo $new_date; 

thanks in advance,

~ realitiez

~~~ edit ~~~

fixed solution wondering how it's done:

html

<form name="filter" method="post">     from:     <input type="date" name="datefrom" value="<?php echo date('y-m-d'); ?>" />     <br/>     to:     <input type="date" name="dateto" value="<?php echo date('y-m-d'); ?>" />     <input type="submit" name="submit" value="login"/> </form> 

php

$new_date = date('y-m-d', strtotime($_post['datefrom'])); echo $new_date; 

special every answer.

validate input.

$time = strtotime($_post['datefrom']); if ($time != false){   $new_date = date('y-m-d', $time));   echo $new_date; } else{    echo 'invalid date: ' . $_post['datefrom'];   // fix it. } 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -