I am trying to get a date from a date input form and I just can't get it to work correctly. The code I'm using now returns an error and this date: 1970-01-01. This is not true, and I would like to know how I can do this. This will be used later to query the database table. I want the date to be basically like a string with this format: "yyyy-mm-dd"
code:
HTML
<form name="DateFilter" method="POST"> From: <input type="date" name="dateFrom" value="<?php echo date('Ym-d'); ?>" /> <br/> To: <input type="date" name="dateTo" value="<?php echo date('Ym-d'); ?>" /> </form>
Php
$new_date = date('Ym-d', strtotime($_POST['dateFrom'])); echo $new_date;
Thanks in advance,
~ Realization
~~~ EDIT ~~~
Fixed solution for everyone who wondered how to do this:
HTML
<form name="Filter" method="POST"> From: <input type="date" name="dateFrom" value="<?php echo date('Ym-d'); ?>" /> <br/> To: <input type="date" name="dateTo" value="<?php echo date('Ym-d'); ?>" /> <input type="submit" name="submit" value="Login"/> </form>
Php
$new_date = date('Ym-d', strtotime($_POST['dateFrom'])); echo $new_date;
Special thanks for every reply.
source share