0

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?

3
Contributors
3
Replies
4
Views
11 Years
Discussion Span
Last Post by nathanpacker
0

Try something like:

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

Try something like:

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

That worked perfectly. I didn't realize I was passing

date("Y-m-d")

to the database and it was expecting

date("Y-m-d H:i:s")

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!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.