944,010 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 7758
  • PHP RSS
Sep 20th, 2006
0

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

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Posting Whiz in Training
nathanpacker is offline Offline
234 posts
since May 2005
Sep 20th, 2006
0

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

Please post a sample of the data you are attempting to enter.
Moderator
Reputation Points: 161
Solved Threads: 38
He's No Good To Me Dead
stymiee is offline Offline
1,422 posts
since May 2006
Sep 20th, 2006
0

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

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]
Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005
Sep 21st, 2006
0

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

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!
Reputation Points: 10
Solved Threads: 0
Posting Whiz in Training
nathanpacker is offline Offline
234 posts
since May 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: php plan for a voting system?
Next Thread in PHP Forum Timeline: Preview Upload Image Problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC