0

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?

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by danishbacker
0

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

0

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();

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.