I Need to insert a date into mysql database i dont know which is better
using DATE or VARCHAR as the date field ??
im using now the DATE type but whenever i insert any date its not inserted in the DB
0000-00-00 it appears like this .

the Code:

$mydate=date("$year.$month.$day");

insert into ....values ($mydate);

i dont know what's wrong

plz help

I Need to insert a date into mysql database i dont know which is better
using DATE or VARCHAR as the date field ??
im using now the DATE type but whenever i insert any date its not inserted in the DB
0000-00-00 it appears like this .

the Code:

$mydate=date("$year.$month.$day");

insert into ....values ($mydate);

i dont know what's wrong

plz help

The dashes are required.

I think there is problem in inserting the values into database can you once check the syntax of insert query or if you provide the query i will look into it

Regardless of what the error is I find it best to store a unix timestamp in the database in a "int" field and then use PHP to manipulate it.

This produces a very fast db table when sorting by date.

This is the best practice until you become more familiar with php and mysql and explore the differences in formatting the date.

To get the unix timestamp do something like:

$unix_time = date('U');

you can then format this by doing:

$formatted_time = date('Y-m-d',$unix_time);

$formatted_time_plus_1_week = date('Y-m-d',strtotime("+1 week",$unix_time));

Very simple.

U know Thanks So much i solved the problem
but now i faced another
when the date is displayed its displayed YYYY-MM-DD
is their anyother way to display it as DD-MM-YYYY ?????????????????
if im storing as DATE

Thank You Very Much POA
but may i ask why are u using
strtotime here ?? why not just say
$newDate=date('d-m-Y');

Thank You Very Much POA
but may i ask why are u using
strtotime here ?? why not just say
$newDate=date('d-m-Y');

That would be fine if you just wanted today's date.

This article has been dead for over six months. Start a new discussion instead.