简体   繁体   中英

PHP mktime include Day of the Week and Month/Day

I have a PHP page that shows information based on the current day of the week and also allows for the ability to +1 or -1 from the current day based on _GET passed in the URL. This is working correctly as you see here where the H2 displays the Day of the week. I also need to display the Month/Day

<legend>
   <h2>
   <?php 
    if (array_key_exists('day', $_GET)) {

    $display_day = mktime(0, 0, 0, date("m")  , date("d") + $add_day, date("Y"));

    $today = date('N', $display_day);

    if( $today == 7) { ?>
    Sunday's
    <?php } elseif( $today == 1 ) { ?>
    Monday's
    <?php } elseif( $today == 2 ) { ?>
    Tuesday's
    <?php } elseif($today == 3 ) { ?>
    Wednesday's
    <?php } elseif( $today == 4 ) { ?>
    Thursday's
    <?php } elseif( $today == 5 ) { ?>
    Friday's
    <?php } elseif( $today == 6 ) { ?>
    Saturday's
    <?php } ?> Employee Schedule</h2>
</legend>

I tried adding the echo $display_day but it is not showing anything like this? What am I missing?

if( $today == 7) { ?>
Sunday's <?php echo $display_day; ?>
<?php } elseif( $today == 1 ) { ?>
Monday's <?php echo $display_day; ?>
<?php } elseif( $today == 2 ) { ?>
Tuesday's <?php echo $display_day; ?>
<?php } elseif($today == 3 ) { ?>
Wednesday's <?php echo $display_day; ?>
<?php } elseif( $today == 4 ) { ?>
Thursday's <?php echo $display_day; ?>
<?php } elseif( $today == 5 ) { ?>
Friday's <?php echo $display_day; ?>
<?php } elseif( $today == 6 ) { ?>
Saturday's <?php echo $display_day; ?>
<?php } ?> Employee Schedule</h2>

You could use the DateTime object.

So you would be able to do this:

$today = new DateTime('today');
$yesterday = $today->modify('-1 day');
$tomorrow = $today->modify('+1 day');

Then you just need to format the date by doing this:

$tomorrow_date = $tomorrow->format('l, F d');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM