...

View Full Version : How to Insert DATE in my SQL using PHP



Saima Nazir
04-13-2012, 02:50 PM
Need Help!!
I have tried it but It is not working..:mad:
//dob column is of DATE datatype

$dob= $_POST['year'] . '-' . $_POST['month'] . '-' .$_POST['day'];
$query=mysql_query("INSERT INTO user(dob) VALUES('$dob')",$con);

lumper
04-13-2012, 03:18 PM
Have you tried using the [icode]date[\icode] handler ...
[icode]$year= date ('yyyy',$year);[\icode]
I am brand new to coding in PHP, but I think this may work...

iswd1
04-13-2012, 03:23 PM
Need Help!!
I have tried it but It is not working..:mad:
//dob column is of DATE datatype

$dob= $_POST['year'] . '-' . $_POST['month'] . '-' .$_POST['day'];
$query=mysql_query("INSERT INTO user(dob) VALUES('$dob')",$con);

The problem is, you're basically just adding number (text) to a DATE field. You need to turn them into an actual date. Do a search for PHP DATE and you'll see what I mean.

Saima Nazir
04-14-2012, 03:09 PM
Yeah I GOT it...
$dob1= $_POST['year'] . '-' . $_POST['month'] . '-' .$_POST['day'];
$time = strtotime( $dob1 );
$dob = date( 'y-m-d', $time );



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum