Date Help
Moderator: General Moderators
Date Help
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
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Re: Date Help
Which version of MySQL are you running?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