Page 1 of 1

Date Help

Posted: Thu Dec 07, 2006 12:17 pm
by hershsa
I was looking for a way to take a date in YYYY-MM-DD format and use that date as the end date for a 7 day stretch. And then also for a 31 day stretch. I need to do mysql queries with each date to get data on each date individually. I guess the date can be in whatever format but just needs to be able to be used in a query. I thought of using date(z) to use the day of the year and just subtract 1 everytime, but I couldn't find a way to switch it back to YYYY-MM-DD format. Thanks

Posted: Thu Dec 07, 2006 1:28 pm
by feyd
Convert the date string to a timestamp with strtotime() or mktime() or MySQL's own functionality. You can then use strtotime() to move forward and backward in time relative to it.

Re: Date Help

Posted: Thu Dec 07, 2006 2:07 pm
by RobertGonzalez
hershsa wrote:I was looking for a way to take a date in YYYY-MM-DD format and use that date as the end date for a 7 day stretch. And then also for a 31 day stretch. I need to do mysql queries with each date to get data on each date individually. I guess the date can be in whatever format but just needs to be able to be used in a query. I thought of using date(z) to use the day of the year and just subtract 1 everytime, but I couldn't find a way to switch it back to YYYY-MM-DD format. Thanks
Which version of MySQL are you running?