PHP Date always returns 0

Thread Solved
Reply

Join Date: Sep 2008
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

 
0
  #1
Dec 4th, 2008
I am trying to insert a date into a mysql table field using
  1. <?php
  2. $date=date(Y-m-d);
  3. mysql_query("INSERT INTO table VALUES('$date')");
  4. ?>

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?
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
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

 
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 Quick reply to this message  
Join Date: Apr 2008
Posts: 75
Reputation: danishbacker is an unknown quantity at this point 
Solved Threads: 5
danishbacker's Avatar
danishbacker danishbacker is offline Offline
Junior Poster in Training

Re: PHP Date always returns 0

 
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 Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC