0

The following code is supposed to check for the first saturday of next month the remove 6 days from it and determine if that todays date is less than that date calculated. It is not working. The IF statement is triggering regardless of whether todays date has exceeded the first saturday of next month - 6 days or not.

<?php $monthdate = date('Y-m-d', strtotime('-6 day', strtotime('first saturday', strtotime('+1 month')))); 
if ($monthdate < date) 

Any ideas?

Marvellous

5
  • 1
    ever had an idea of printing the result out instead of just checking it in if statement? Mar 30, 2011 at 11:31
  • 1
    as well as all intermediate results, to see if any of them returns not expected value? Mar 30, 2011 at 11:32
  • var_dump($monthdate) and var_dump($date) and var_dump($monthdate < date)
    – Treffynnon
    Mar 30, 2011 at 11:32
  • Yes the values are not timestamps, thats the problem. $monthdate should be a UNIX timestamp, how do I make it one. And date should be todays date as a UNIX timestamp and is not. Any ideas?
    – Walrus
    Mar 30, 2011 at 11:37
  • 1
    date is a constant. Is that at typo you made here? If not, then you would have gotten a notice (or is it a warning?) if you have error_reporting set to E_ALL | E_STRICT and turned on displaying of errors. (consider that a hint ;-)). Mar 30, 2011 at 11:38

1 Answer 1

0

There was a conflict between 2 functions and also the date not being properly formatted as a time stamp. For the community I give the answer.

<?php $monthdate = date(strtotime('first saturday', strtotime('-8 day', strtotime('+1 month', strtotime(date("01-m-Y")))))); 

if ($monthdate < time())

$monthdate returns a UNIX timestamp of the first saturday of next month. The function strtotime(date("01-m-Y")) is required to make sure that if todays date is higher in day terms the first saturday of the next month ie. if the first saturday of this month is the 5th and next month the 2nd, that it gets the 2nd as the first saturday not the 9th. Simple mathmatical adjustment of where to begin its search.

This is then subtracted by 8 days and compared with a UNIX timestamp of the current date and time time();

Purpose

Providing an online booking calendar that takes bookings on the first saturday of each month.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.