help with day today and yesterday

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
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

help with day today and yesterday

Post by pleigh »

hi community,

i have this problem and could not formulate a logic regarding dates/days. the scenarion is:

i have a search feature on my site and a filter for dates. in the dropdown, i have items from Monday to Sunday. if today is Wednesday then i selected "Monday" from the list, what i will get is the result for Monday the following week.same goes if i select "Tuesday". BUT if i select Wednesday, Thursday, Friday, Saturday, Sunday, i wll be able to get results from this week. i hope someone could provide me a logic as i hae spent 2 days doing this.

thanks in advance
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: help with day today and yesterday

Post by Celauran »

Have your select list dynamically generated based on the current day, and have the value be the number of days ahead of today. From there, just use DateTime::modify().
Post Reply