Date Help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hershsa
Forum Newbie
Posts: 1
Joined: Thu Dec 07, 2006 12:07 pm

Date Help

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Date Help

Post 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?
Post Reply