form date

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jamrop
Forum Commoner
Posts: 80
Joined: Fri May 16, 2003 5:38 pm

form date

Post 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
Stoneguard
Forum Contributor
Posts: 101
Joined: Wed Aug 13, 2003 9:02 pm
Location: USA

Post 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;
}
?>
leebo
Forum Commoner
Posts: 44
Joined: Sun Oct 20, 2002 9:49 am

Post 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;
?>
Post Reply