Roych Posted December 19, 2022 Share Posted December 19, 2022 Hello, I need some help with simple restaurant food menu, I'd like to show yesterdays menu and 6 future days (all together 7 days). My problem is that I'm not sure how to show -1 day with all future days. Another problem I have is that I don't need time in my datetime field ("Start_date") the menu should stay there entire day till midnight. But the day starts with 0:00:00 hrs and if I want the past event to go to trash, it goes in the morning not at midnight. (it puts todays event in the trash) Kind a lost here. it should show days like Wednesday (yesterday) | Thursday (today) | Friday | Saturday | Sunday | etc ... I show my "events" with <?php $events = $pages->find("template=calendar-post, Start_date>=today-1, sort=end, limit=7"); ?> <?php if(count($events)): ?> // my event code For dates I also tried with: <?php $today = date('d. m. Y'); $start = date('d. m. Y', $single->getUnformatted('Start_date') . " 00:00:00"); ?> And for trash I use: <?php $ptrashed = $pages->find("template=calendar-post"); foreach($ptrashed as $ptrash) { if(time() > $ptrash->getUnformatted("Start_date")) { $pages->trash($ptrash); } } ?> I'm not good with php so any help appreciated. Thank you very much for helping. R Link to comment Share on other sites More sharing options...
wbmnfktr Posted December 19, 2022 Share Posted December 19, 2022 This should do the trick to get all events from yesterday and the next 6 days. // define yesterday $yesterday = strtotime("-1 day"); // make $yesterday match the saved date format // in this case: dd.mm.yyyy $yesterdayForSelector = date('d.m.Y', $yesterday); // get our pages $events = $pages->find("template=template, limit=7, date>=$yesterdayForSelector"); 3 Link to comment Share on other sites More sharing options...
Roych Posted December 19, 2022 Author Share Posted December 19, 2022 2 hours ago, wbmnfktr said: // define yesterday $yesterday = strtotime("-1 day"); // make $yesterday match the saved date format // in this case: dd.mm.yyyy $yesterdayForSelector = date('d.m.Y', $yesterday); // get our pages $events = $pages->find("template=template, limit=7, date>=$yesterdayForSelector"); Nice, it works great. Now only the datetime and putting in the trash. Defining the $yesterday simple. Thank you very much ;) 1 Link to comment Share on other sites More sharing options...
Roych Posted December 20, 2022 Author Share Posted December 20, 2022 Not sure for trashing the events but would something like this work? I need to leave yesterday published but all older ones put in a trash. <?php $preyesterday = strtotime("-2 days"); $ptrashed = $pages->find("template=calendar-post, Start_date>=$preyesterday"); foreach($ptrashed as $ptrash) { if(time($preyesterday) > $ptrash->getUnformatted("Start_date")) { $pages->trash($ptrash); } } ?> or <?php $eventpages = wire("pages")->find("template=calendar-post, include=all"); foreach ($eventpages as $eventpage) { $enddate = $eventpage->Start_date; $currenttime = time("-2 days"); if ($enddate < $currenttime) { $pages->trash($eventpage); } } ?> Thank you R Link to comment Share on other sites More sharing options...
wbmnfktr Posted December 20, 2022 Share Posted December 20, 2022 Either I'm missing an important detail or ... // define yesterday $theDayBeforeYesterday = strtotime("-2 day"); // get our pages $reallyOldEvents = $pages->find("template=template, date<=$theDayBeforeYesterday"); foreach($reallyOldEvents as $oldEvent){ // let's do something with it // maybe we put them into an archive // and delete all of them in 2 years // rather than now. } Does this find your events prior to yesterday? 2 Link to comment Share on other sites More sharing options...
Roych Posted December 21, 2022 Author Share Posted December 21, 2022 18 hours ago, wbmnfktr said: Does this find your events prior to yesterday? yes it does, it looks like it's working. Thank you very much. Actualy learnt something new here. ? R 1 Link to comment Share on other sites More sharing options...
wbmnfktr Posted December 21, 2022 Share Posted December 21, 2022 5 hours ago, Roych said: Actualy learnt something new here. Which part was new? Date handling? That will forever be a mystery. 1 Link to comment Share on other sites More sharing options...
Roych Posted December 21, 2022 Author Share Posted December 21, 2022 30 minutes ago, wbmnfktr said: Which part was new? Date handling? That will forever be a mystery. hehe ? Well defining stuf and the calling them out. ? 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now