Page 1 of 1

form date

Posted: Tue Oct 07, 2003 5:44 pm
by jamrop
hey

Can anyone help me

I have a form and one of the fields is date. I call the database to show the date in the input type, so it shows e.g. 13th Oct 03. I have put this code to put it into that format

Code: Select all

<?php
$date = strtotime($r["date"]);
$date = date("dS M y", $date );

?>
The problem that i am getting is that if i change the date in the input type, it does not work.

I am thinking when it updates the database, do i have to convert the date i entered to the database date format?? if it is , i am not sure how to do that

many thanks for your help

Posted: Tue Oct 07, 2003 5:47 pm
by Stoneguard
Depends on your database, but if you are using MySQL, it is a good idea to use ISO formatted dates. I wrote a simple function to convert my input dates to ISO:

Code: Select all

<?php
function iso_date($val)
{
   $dt = date("Y-m-d H:i:s", strtotime($val));
   return $dt;
}
?>

Posted: Sat Oct 11, 2003 5:16 am
by leebo
If you are pulling from the database then you could use:

Code: Select all

<?php
$date = $row["date"];
list($day, $month, $year) = split('[/.-]', $date);
$mysqldate = "$year-$month-$day";
echo $mysqldate;
?>