Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Best way to show written date and some weekend rules

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Best way to show written date and some weekend rules

Postby srmobile » Mon Oct 21, 2013 10:22 am

Hello,

So I've needed to create a script that will show tomorrows date, with the exception of Friday, Saturday and Sunday as I would like to show that option as Monday and a countdown timer that expires at 2PM every day.

So far I have:

Code: Select all
 <?php date_default_timezone_set('America/New_York'); ?>
         <?php echo $this->__('Order in the next ') ?>
               
               <?php date_default_timezone_set('America/New_York');
                  $today = strtotime('today 14:00');
                  $tomorrow = strtotime('tomorrow 14:00');
                  $now = time();
                  $timeLeft = ($now > $today ? $tomorrow : $today) - $now;
                  printf("%s\n", gmdate("H:i", $timeLeft));?>
                  <?php echo $this->__('and receive your order ') ?><?php $date = date("d-M-y", strtotime("tomorrow")); echo $date; ?>


Perfect, but how would I throw in the Friday, Saturday, Sunday variables?

Also is it possible to display the date written out example: Monday, October 21 ?

Thanks!

SR
srmobile
New php-forum User
New php-forum User
 
Posts: 2
Joined: Mon Oct 21, 2013 9:59 am

Re: Best way to show written date and some weekend rules

Postby simplypixie » Tue Oct 22, 2013 11:14 pm

This is what you need:

Code: Select all
<?php
                     $date = date("l\, F j", strtotime("tomorrow"));
                     $day = date('l', strtotime('tomorrow'));
                     if ($day == 'Friday' || $day == 'Saturday' || $day == 'Sunday') {
                        echo 'Monday';
                     } else {
                        echo $date;
                     }
                  ?>
User avatar
simplypixie
php-forum Active User
php-forum Active User
 
Posts: 300
Joined: Sun Dec 11, 2011 12:51 am
Location: Shrewsbury, Shropshire

Re: Best way to show written date and some weekend rules

Postby srmobile » Wed Oct 23, 2013 3:35 am

Thanks simplixie!

How would I address the time issue?

IE: When it hits Friday, Saturday or Sunday it will still say "Order by 14:00" and be counting down.

Thanks again,

SR
srmobile
New php-forum User
New php-forum User
 
Posts: 2
Joined: Mon Oct 21, 2013 9:59 am


Return to PHP coding => General

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.