RSS Forums RSS

PHP Date always returns 0

Thread Solved
Reply
Posts: 6
Reputation: pocnib is an unknown quantity at this point 
Solved Threads: 0
pocnib pocnib is offline Offline
Newbie Poster

PHP Date always returns 0

  #1  
Dec 4th, 2008
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?
AddThis Social Bookmark Button
Reply With Quote  
Posts: 6
Reputation: pocnib is an unknown quantity at this point 
Solved Threads: 0
pocnib pocnib is offline Offline
Newbie Poster

Re: PHP Date always returns 0

  #2  
Dec 4th, 2008
It was quotes around the date format string. Why does the obvious always become obvious only after you ask for help?
Reply With Quote  
Posts: 72
Reputation: danishbacker is an unknown quantity at this point 
Solved Threads: 4
danishbacker's Avatar
danishbacker danishbacker is offline Offline
Junior Poster in Training

Re: PHP Date always returns 0

  #3  
Dec 15th, 2008
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();
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Views: 500 | Replies: 2 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:22 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC