Page 1 of 1

Sending user input date of birth to mysql database

Posted: Mon May 10, 2010 11:27 am
by geoffmuskett
Hi, I'm trying to collect a users date of birth when they register but am struggling to send it to the database in the correct format (or any format!). This is what I have:

Code: Select all

$dob_eploded = explode("/", $dob);	
	$dob_timestamp = mktime(0,0,0,$dob_eploded[0], $dob_eploded[1], $dob_eploded[2]);
$dob is the value they sent in the format dd/mm/yyyy. The database stores them in the this format: 0000-00-00 00:00:00.

When the mysql query with $dob_timestamp is sent there's no error, the database just isn't updating.

Thanks,

Geoff

Re: Sending user input date of birth to mysql database

Posted: Mon May 10, 2010 11:39 am
by wurdup
geoffmuskett wrote:Hi, I'm trying to collect a users date of birth when they register but am struggling to send it to the database in the correct format (or any format!). This is what I have:

Code: Select all

$dob_eploded = explode("/", $dob);	
	$dob_timestamp = mktime(0,0,0,$dob_eploded[0], $dob_eploded[1], $dob_eploded[2]);
$dob is the value they sent in the format dd/mm/yyyy. The database stores them in the this format: 0000-00-00 00:00:00.

When the mysql query with $dob_timestamp is sent there's no error, the database just isn't updating.

Thanks,

Geoff
are you putting the $dob_timestamp in the correct way? atm you have it in the wrong sequence. If the format is wrong the data will just show as 0000-00-00 00:00:00 in the db. you need to put y-m-d time in mysql

Re: Sending user input date of birth to mysql database

Posted: Tue May 11, 2010 3:38 am
by geoffmuskett
Cheers wurdup!

This works (may not be the best solution, but hey):

Code: Select all

$dob_eploded = explode("/", $child_dob);	
$date_formatted = $dob_eploded[2] . "-" . $dob_eploded[1] . "-" . $dob_eploded[0] . " 00:00:00";

Re: Sending user input date of birth to mysql database

Posted: Tue May 11, 2010 8:41 am
by AbraCadaver
Why not use date time functions?

Code: Select all

$dob = date('Y-m-d', strtotime($dob));