mysql date ALWAYS = 0000-00-00 00:00:00

Reply

Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

mysql date ALWAYS = 0000-00-00 00:00:00

 
0
  #1
Sep 20th, 2006
Hey, I've got a form that passes the date onto a php script, which posts all the form entries into a database. One of those fields happens to be a date field. I have it going into a column in a mysql database that has the DATETIME datatype, but no matter how I work the code, it always goes into the database as 0000-00-00 00:00:00. I know I'm passing the date correctly through the form, because I've echo'd out the variable and it shows the correct date. I'm thinking my problem is on the mysql database, but can't figure it out!

For now, I've just changed the datatype to VARCHAR in that field, and it's working, but I'd very much like to use the DATETIME datatype. Any ideas?
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,422
Reputation: stymiee is on a distinguished road 
Solved Threads: 35
Moderator
stymiee's Avatar
stymiee stymiee is offline Offline
He's No Good To Me Dead

Re: mysql date ALWAYS = 0000-00-00 00:00:00

 
0
  #2
Sep 20th, 2006
Please post a sample of the data you are attempting to enter.
John Conde
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,082
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: mysql date ALWAYS = 0000-00-00 00:00:00

 
0
  #3
Sep 20th, 2006
Try something like:

[php]
function mysql_date($year, $month, $day, $hour, $min, $sec) {
return date("Y-m-d H:i:s", mktime($hour, $min, $sec, $month, $day, $year));
}
[/php]
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

Re: mysql date ALWAYS = 0000-00-00 00:00:00

 
0
  #4
Sep 21st, 2006
Originally Posted by digital-ether View Post
Try something like:

[php]
function mysql_date($year, $month, $day, $hour, $min, $sec) {
return date("Y-m-d H:i:s", mktime($hour, $min, $sec, $month, $day, $year));
}
[/php]

That worked perfectly. I didn't realize I was passing [PHP]date("Y-m-d")[/PHP] to the database and it was expecting [PHP]date("Y-m-d H:i:s")[/PHP]

Hey, I learn something new on this forum every day. And I also found a chart on the php website that shows all the time tags to put in. Thanks for the info!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC