Day of week ?

5 posts by 2 authors in: Forums > CMS Builder
Last Post: April 11, 2017   (RSS)

By kovali - April 6, 2017

Hi,

My client wants to post the openinghours for each day of the week on his homepage, like:

(On Mondays:) "Sorry we are closed today"
(On Tuesdays:) "Today we are open from 08.00 - 17.00"
etc...

Is there a way in PHP to determine what day (sunday, monday, tuesday, ...) it is and to post the correct line for that day pls ??

Thx in advance !

Koen

By kovali - April 6, 2017

Hi, 

No, I'm thinking of something that will override the standard message when they enter some text manually for that day...

By mizrahi - April 6, 2017

1. Setup a Single Record Editor

2. Add fields for mon,tue,wed,thu,fri,sat,sun

3. Add your hours

4. connect your webpage to this new editor

4. Use this code where you want the message to appear

   <?php if (date("N")==1): ?>
      <?php if($hoursRecord['mon']=="Closed"): ?>
         Sorry, we are closed today.
      <?php else: ?>
         Today we are open from <?php echo htmlencode($hoursRecord['mon']) ?>
      <?php endif; ?>
   <?php endif; ?>
   <?php if (date("N")==2): ?>
      <?php if($hoursRecord['tue']=="Closed"): ?>
         Sorry, we are closed today.
      <?php else: ?>
         Today we are open from <?php echo htmlencode($hoursRecord['tue']) ?>
      <?php endif; ?>
   <?php endif; ?>
   <?php if (date("N")==3): ?>
      <?php if($hoursRecord['wed']=="Closed"): ?>
         Sorry, we are closed today.
      <?php else: ?>
         Today we are open from <?php echo htmlencode($hoursRecord['wed']) ?>
      <?php endif; ?>
   <?php endif; ?>
   <?php if (date("N")==4): ?>
      <?php if($hoursRecord['thu']=="Closed"): ?>
         Sorry, we are closed today.
      <?php else: ?>
         Today we are open from <?php echo htmlencode($hoursRecord['thu']) ?>
      <?php endif; ?>
   <?php endif; ?>
   <?php if (date("N")==5): ?>
      <?php if($hoursRecord['fri']=="Closed"): ?>
         Sorry, we are closed today.
      <?php else: ?>
         Today we are open from <?php echo htmlencode($hoursRecord['fri']) ?>
      <?php endif; ?>
   <?php endif; ?>
   <?php if (date("N")==6): ?>
      <?php if($hoursRecord['sat']=="Closed"): ?>
         Sorry, we are closed today.
      <?php else: ?>
         Today we are open from <?php echo htmlencode($hoursRecord['sat']) ?>
      <?php endif; ?>
   <?php endif; ?>
   <?php if (date("N")==7): ?>
      <?php if($hoursRecord['sun']=="Closed"): ?>
         Sorry, we are closed today.
      <?php else: ?>
         Today we are open from <?php echo htmlencode($hoursRecord['sun']) ?>
      <?php endif; ?>
   <?php endif; ?>

By kovali - April 11, 2017

Thx, tried it and works very well !!