Submitted date and retrieved date differnet

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
duckula
Forum Newbie
Posts: 2
Joined: Wed Jun 04, 2003 1:35 am
Location: UK

Submitted date and retrieved date differnet

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
duckula
Forum Newbie
Posts: 2
Joined: Wed Jun 04, 2003 1:35 am
Location: UK

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