Re: Confused overSimple PHP mySQL date question

From: Date: Tue, 14 Sep 2004 19:24:16 +0000
Subject: Re: Confused overSimple PHP mySQL date question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-196645@lists.php.net to get a copy of this message
From: "Scott Miller" <smaction@slightlysuspect.com>
I have a mysql database that has a date field and a time field. I want users to be able to enter a date and a time in text boxes on an html form and have them end up in the database.
Code examples would be good here. Either way, the format for a DATE field is YYYYMMDD or 'YYYY-MM-DD' and the format for a TIME field is HHMMSS or 'HH:MM:SS'. Make sure what you're trying to stick in the database is in that format. If you want to accept another format in your text fields, then you'll need to use date(), strtotime(), mktime(), explode(), etc to format it this way. You really just need one DATETIME or TIMESTAMP field, though... there's reason to keep these values in two separate fields if they are related to the same event. It'll make searching down the road easier. SELECT * FROM events WHERE datetimecolumn BETWEEN NOW() AND INTERVAL + 30 DAY; SELECT * FROM events WHERE datetimecolumn BETWEEN 20040901 AND 20040930; etc... ---John Holmes...

« previous php.general (#196645) next »