Page 1 of 1

Submitted date and retrieved date differnet

Posted: Wed Jun 04, 2003 1:35 am
by duckula
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.

Posted: Wed Jun 04, 2003 1:57 am
by volka
you might let mysql do the work.

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_time_types.html
http://www.mysql.com/doc/en/Date_and_ti ... tions.html

Posted: Fri Jun 06, 2003 6:13 am
by duckula
Thanks for that , will give it a go.

On a different subject , is it possible to define an array of <option> controls. Using Javascript I can dynamically add further lists but I then want to be able to iterate through them during a post.

Cheers