php – strtotime only tracks 1 week in advance – Education Career Blog

Using the following if statement I am trying to check whether the day of the week is Friday

if(($uur < 12) && ($min < 30) && ($datum == date('Y-m-d', strtotime('Friday'))))
{  
  $proceed = FALSE;  
  $errorWoensdagVrijdag = "<div id='row_form_dropdown'>Error Message</div>";  
}

The dates are being inserted using a form. Everything is being checked just fine, when I try and select date and time on friday the 22nd before 12:30 i’ll receive an error message. But should I check it on Friday the 27th it’ll just pass through without any complications.

I’m at a bit of a loss here since to me it seems that it should just be working. I’ve seen some remarks in regards to the PHP version, i’m running PHP Version 5.2.9.

Anyone that would like to offer their assistance is more than welcome.

,

It’s because strtotime('Friday') means “Friday this week”.

You should use:

if(date('N', $timestamp) == 5)
{
    // Friday!
}
else
{
    // Not Friday :-(
}

I guess in your case the date the user entered is in $datum. Your if statement would become:

if(($uur < 12) && ($min < 30) && (date('N', strtotime($datum)) == 5))
{
    $proceed = FALSE;
    // Etc..
}

For more info about the use of date('N', $timestamp), see: http://php.net/manual/en/function.date.php

,

NEW IDEA

$timestamp=mktime(0, 0, 0, 10, 21, 2010);
$today = getdate($timestamp);
echo $today"weekday";

OLD IDEA
Another way of doing it is:

  <?php
     $h = mktime(0, 0, 0, 10, 31, 2008);
     $d = date("F dS, Y", $h) ;
     $w= date("l", $h) ;
//     Echo "$d is on a $w";

if($w=="Friday"){
echo "Yes";
}
     ?>

Whole article:http://php.about.com/od/finishedphp1/qt/dayoftheweek.htm

Where 10,31,2008 is your date.

Leave a Comment