Sorry to bother you with this again, but I am blocked for the last 2 days.
PHP and SQL.
I display my date from SQL in a form for user to update like that
<input type="text" name="date" size="20" value="<?php echo date("d/m/Y",strtotime($date));?>">
When user post this value I get it back that way
$date = $_POST["date"];
$date = date('Y-m-d h:i:s',strtotime($date));
now if in my form i enter a date like 15/12/1999, this updated properly
BUT
if i enter a date liuke 15/12/2004, the DB is update with the value
12/03/2005 12:00:00
something i am missing there???
thanks in advance
s
Really need some help on that one
Moderator: General Moderators
You could do something like:
Code: Select all
$dparts = explode('/', $_POST['date']);
$date = date('Y-m-d h:i:s', strtotime($dparts[1].'/'.$dparts[0].'/'.$dparts[2]));That worked perfectly mark!
Thanks for your input.
I repeat the code below for people that needs it:
Display date in a input ready for update:
<input type="text" name="date" size="20" value="<?php echo date("d/m/Y",strtotime($date));?>">
User submit the form with whatever value and I get the info like that
$date = $_POST["date"];
$dparts = explode('/', $date);
$date = date('Y-m-d h:i:s', strtotime($dparts[1].'/'.$dparts[0].'/'.$dparts[2]));
date is displayed properly...
Last little question...
Any good function to check that the date is in correct format?
thanks again
s
Thanks for your input.
I repeat the code below for people that needs it:
Display date in a input ready for update:
<input type="text" name="date" size="20" value="<?php echo date("d/m/Y",strtotime($date));?>">
User submit the form with whatever value and I get the info like that
$date = $_POST["date"];
$dparts = explode('/', $date);
$date = date('Y-m-d h:i:s', strtotime($dparts[1].'/'.$dparts[0].'/'.$dparts[2]));
date is displayed properly...
Last little question...
Any good function to check that the date is in correct format?
thanks again
s