RE: [PHP] Best way for date/time

From: Date: Sat, 11 May 2002 17:59:42 +0000
Subject: RE: [PHP] Best way for date/time
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-97127@lists.php.net to get a copy of this message
> Okay so I've then got > > 2002-05-08 > and whats then the best way to manipulate it regarding > plus 3 days or plus 4 weeks ? I definitely agree to use the MySQL format for your dates. It makes it easier to use the built in functions. You can convert the timestamp to a unix style if you have to, also. Read the manual on the date and time functions, there are a ton of them. As for your question, you can do things like that quite easily. SELECT * FROM table WHERE datetime_column BETWEEN CURDATE() AND CURDATE() + INTERVAL 3 DAY; A query like that will select all rows that have a datetime_column value between the current date and three days from now. Substitute DAY for MONTH, YEAR, etc...and it's easy to get whatever you want out of the query. Use DATE_FORMAT() in your query to format the date from YYYY-MM-DD HH:MM:SS to whatever format you want...similar to date() in PHP. ---John Holmes...

« previous php.general (#97127) next »