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?

Recommended Answers

All 3 Replies

Please post a sample of the data you are attempting to enter.

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));
}

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.