2

I would like to check with PHP or JavaScript the day if it's a weekend or not. If it's a normal week day it should echo the current time an the date from next day but if today is Saturday/Sunday then it should echo "please try it Tuesday (but not the day name it should show the date)".

Sam
  • 7,252
  • 16
  • 46
  • 65
Gaven
  • 21
  • 1
  • 6
  • 3
    In PHP, a [date format mask](http://www.php.net/manual/en/function.date.php) of `N` returns the day of the week as a number where 1 is Monday and 7 is Sunday, so if that value is `>5` it's the weekend – Mark Baker Jan 19 '14 at 11:44
  • 1
    Possible duplicate of [Checking if date is weekend PHP](http://stackoverflow.com/questions/4802335/checking-if-date-is-weekend-php) – cura Jun 23 '16 at 18:54

2 Answers2

6
<?php 
    if(date("w") == 0 or date("w") == 6){
       //weekend
    } 
?>

date(): date("w") returns the current day of the week in numbers (0 for Sunday and 6 for Saturday).

zurfyx
  • 31,043
  • 20
  • 111
  • 145
2

This will return you 0 to 6, with 0=Sunday, 1=Monday, etc.

$dw = date( "w", $timestamp);

So... to show the notification:

<?php
    $dw = date( "w");
    if ($dw == 6 || $dw == 0) {
        $datetime = new DateTime('today');
        if ($dw == 6) {
            $datetime->modify('+3 day');
        } else {
            $datetime->modify('+2 day');
        }
        echo "Contact us again at: " . $datetime->format('Y-m-d');
    } else {
        echo "Today is: " . date('l jS \of F Y')."<br/>";
        $datetime = new DateTime('today');
        $datetime->modify('+1 day');
        echo "Tomorrow is: ". $datetime->format('Y-m-d') ."<br/>";
    }
?>
  • Ok cool really thanks, but that's only the notification for weekend but how to combine it for the normal week day (Monday .... Friday) where it should echo the current time and also the next day date ( with the next day date it's the same like your write) but how to combine the code best way – Gaven Jan 19 '14 at 12:15
  • everything looks good but the result for Tomorrow is: 86404 don't know why – Gaven Jan 19 '14 at 22:10
  • and also Contact us again at: " . $newdate; results nothing – Gaven Jan 19 '14 at 22:45
  • Ok all works now, but how can I change the result to german I think with setlocale(LC_TIME, 'de_DE'); or but nothing – Gaven Jan 21 '14 at 00:02
  • You can use date_default_timezone_set('Europe/Berlin'); in the beginning of the script. – Aggelos Synadakis Jan 21 '14 at 10:28