funstad Posted November 17, 2014 Share Posted November 17, 2014 (edited) Hey all, I'm trying to build a dynamic store opening hours display (see image below) what I have: as you can see on the image above, a red box shows what day it is today. When the store is open 09:00 till 12:00 and 13:00 till 18:00 the red box will change into a green one. When closed a red box appears. Holidays are calculated in PHP Closed days are stored in MYSQL and pulled in php what I still need: I'm searching for a easy and correct way to check if for example today is 17/11/2014 If there is going to be a holiday or a closed day within 7 days. (18,19,20,21,22,23/11/2014) If there is a holiday or closed day within 7days it had to been displayed (Arrow on image) Something like this: if (is_a_holiday == true && Monday) {echo $date_of_holiday} else if (is_closed == true && Monday) {echo $date_of_closed} else {echo $Display_regular_Monday} if (is_a_holiday == true && Thuesday) {echo $date_of_holiday} else if (is_closed == true && Thuesday) {echo $date_of_closed} else {echo $Display_regular_Thuesday} // Other days calculation ... Holidays are callculated this way: <?php// vvvvv HOLIDAYS vvvvv // START$Jaar = date('Y'); // Current Year$dezeweek1 = date('Y/m/d'); // Current Day$dezeweek7 = date('Y/m/d', strtotime("+7 day")); // Current Day + 7 Days$EA = easter_date($Jaar); // Easter This Year$ED = date('j', $EA); // Easter Day$EM = date('n', $EA); // Easter Month$EY = date('Y', $EA); // Easter Year $feestdag_01 = date('Y/m/d', mktime (0,0,0,1,1,$Jaar)); // Newyear$feestdag_02 = date('Y/m/d', mktime (0, 0, 0, $EM, $ED + 1, $EY)); // Easter Monday$feestdag_03 = date('Y/m/d', mktime (0,0,0,5,1,$Jaar)); // Labor Day$feestdag_04 = date('Y/m/d', mktime (0, 0, 0, $EM, $ED + 39, $EY)); // Our Dear Lord Ascension$feestdag_05 = date('Y/m/d', mktime (0, 0, 0, $EM, $ED + 50, $EY)); // Pinkster Monday$feestdag_06 = date('Y/m/d', mktime (0,0,0,7,21,$Jaar)); // Nationale feestdag$feestdag_07 = date('Y/m/d', mktime (0,0,0,8,15,$Jaar)); // Our Dear Lady Assumption$feestdag_08 = date('Y/m/d', mktime (0,0,0,11,1,$Jaar)); // All Hallows$feestdag_09 = date('Y/m/d', mktime (0,0,0,11,11,$Jaar)); // Truce$feestdag_10 = date('Y/m/d', mktime (0,0,0,12,25,$Jaar)); // Christmas $feestdag_15 = date('Y/m/d', mktime (0,0,0,11,18,$Jaar)); // Test Date$feestdag_16 = date('Y/m/d', mktime (0,0,0,11,19,$Jaar)); // Test Date// ^^^^^ HOLIDAYS ^^^^^ // END?> English is not my mother language so if my syntax is not correct I apologize Thank you. Edited November 17, 2014 by funstad Link to comment Share on other sites More sharing options...
niche Posted November 17, 2014 Share Posted November 17, 2014 There's many different ways to identify a date: http://www.w3schools.com/php/php_ref_date.asp Link to comment Share on other sites More sharing options...
funstad Posted November 17, 2014 Author Share Posted November 17, 2014 (edited) There's many different ways to identify a date: http://www.w3schools.com/php/php_ref_date.asp Mmhh I dont think the solution can be found there? I'm looking how i can check if there is a holiday from the list that will occurs between today and 7 days if so i have to know witch day it is (mon, thu, wen, ..) something like : if (is_a_holiday == true) {echo $date_of_holiday} else if (is_closed == true) {echo $date_of_closed} else {echo $Display_regular} Edited November 17, 2014 by funstad Link to comment Share on other sites More sharing options...
justsomeguy Posted November 17, 2014 Share Posted November 17, 2014 The mktime function returns a Unix timestamp, you can use that to check. You can use the date function to format the date for display, but the timestamps are what you use to do date math and comparisons. The timestamp is in seconds. Each day has 86400 seconds. So, a date a week from now is today + (86400 * 7). If you have all of your dates as timestamps then you can just use regular math to compare everything. Link to comment Share on other sites More sharing options...
niche Posted November 17, 2014 Share Posted November 17, 2014 mktime() is on the list. You'll probably need a table containing the holidays. Link to comment Share on other sites More sharing options...
funstad Posted November 17, 2014 Author Share Posted November 17, 2014 mktime() is on the list. You'll probably need a table containing the holidays. i already have one ? $feestdag_01 = date('Y/m/d', mktime (0,0,0,1,1,$Jaar)); // Newyear$feestdag_02 = date('Y/m/d', mktime (0, 0, 0, $EM, $ED + 1, $EY)); // Easter Monday$feestdag_03 = date('Y/m/d', mktime (0,0,0,5,1,$Jaar)); // Labor Day$feestdag_04 = date('Y/m/d', mktime (0, 0, 0, $EM, $ED + 39, $EY)); // Our Dear Lord Ascension$feestdag_05 = date('Y/m/d', mktime (0, 0, 0, $EM, $ED + 50, $EY)); // Pinkster Monday$feestdag_06 = date('Y/m/d', mktime (0,0,0,7,21,$Jaar)); // Nationale feestdag$feestdag_07 = date('Y/m/d', mktime (0,0,0,8,15,$Jaar)); // Our Dear Lady Assumption$feestdag_08 = date('Y/m/d', mktime (0,0,0,11,1,$Jaar)); // All Hallows$feestdag_09 = date('Y/m/d', mktime (0,0,0,11,11,$Jaar)); // Truce$feestdag_10 = date('Y/m/d', mktime (0,0,0,12,25,$Jaar)); // Christmas 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