I am trying to insert a date into a mysql table field using

<?php
$date=date(Y-m-d);
mysql_query("INSERT INTO table VALUES('$date')");
?>

but when I open up mysql and run SELECT * FROM table; it returns a date value of 0000-00-00 instead of the current date at time of insert. Am I misunderstanding something with the php date function?

It was quotes around the date format string. Why does the obvious always become obvious only after you ask for help?

i think you have to use date_default_timezone_set('yourtime zone'); for me it is as follows date_default_timezone_set('Asia/Calcutta'); then call date();

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.