This is the pseudo code, I get a date from the user and convert it to Unix timestamp
$unix_DOB = UnixTimeFromDateString($POST['DOB_Day'],$_POST['DO
B_Month'],$_POST['DOB_Year']);
This is the function UnixTimeFromDateString
function UnixTimeFromDateString($day,$month,$year) {
$unixtime = mktime(0,0,0,$month,$day,$year);
return $unixtime;
}
This is then stored in a mySQL database table. The database field is defined as bigint. I have tried timestamp but then I could not insert the record !
When I retrieve the record I then do
$dayToSelect = date("d",$selectedUnixDate);
$monthToSelect = date("m",$selectedUnixDate);
$yearToSelect = date("Y",$selectedUnixDate);
This is performed this way because I am populating a list box and use the ToSelect variable to select that component in the list box.
The problem is that after doing the conversion back to day month year I do not get the same date that was entered, for example,
02/02/1990 gets stored as 633747600, when retrieved and reformatted it is now 31/01/1990.
Any ideas or assistance would be greatly appreciated.
Submitted date and retrieved date differnet
Moderator: General Moderators
you might let mysql do the work.
http://www.mysql.com/doc/en/Date_and_time_types.html
http://www.mysql.com/doc/en/Date_and_ti ... tions.html
Code: Select all
<?php
/** insert */
$date = "'" . $_POST['DOB_Year'] . '-' . $_POST['DOB_Month'] . '-' . $POST['DOB_Day'] . "'";
$query = 'INSERT INTO myTable (myTimestamp) VALUES (' . $date . ')';
...
/** retrieve */
$query = "SELECT date_format(myTimestamp, '%M %D, %Y') from myTable";
...
?>http://www.mysql.com/doc/en/Date_and_ti ... tions.html