DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   PHP (http://www.daniweb.com/forums/forum17.html)
-   -   PHP Date always returns 0 (http://www.daniweb.com/forums/thread160760.html)

pocnib Dec 4th, 2008 4:11 pm
PHP Date always returns 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?

pocnib Dec 4th, 2008 4:22 pm
Re: PHP Date always returns 0
 
It was quotes around the date format string. Why does the obvious always become obvious only after you ask for help?

danishbacker Dec 15th, 2008 5:27 am
Re: PHP Date always returns 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();


All times are GMT -4. The time now is 7:03 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC