tags:

views:

28

answers:

2

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.

+2  A: 

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

captaintokyo
Now it might just be one of those days but I'm still at loss what you're suggesting. So strtotime('Friday') will only check for the Friday this week. But how would I go about implementing your solution in my code, wouldn't 5 check whether or not the date selected is he fifth?
Roswell Balentien
No 5 means "5th day of the week" (starting from Monday). I updated my answer for you case...
captaintokyo
You're absolutely right, thank you very much for your extremely swift response and the function reference. Time to do some more reading!
Roswell Balentien
You're welcome.
captaintokyo
+1  A: 

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.

netadictos
Thanks a lot for the code reference, it was a very insightful read.
Roswell Balentien