tags:

views:

59

answers:

1

What I am trying to do is I have a selected date formatted as below:

$selectedDate = 2010/02/24 

I want to check it is both todays date and it is past 9pm on the server and set a value if it is.

I can get a time by using the following:

$checkTime = date("H:i");

I want to create something like:

if ($checkTime > 21:00 && $selectedDate == date("Y/m/d")) { //do my stuff }

But a bit unsure of the syntex.

Many thanks for any help

+4  A: 
$checkDate = '2010-02-24';
$checkTime = '2100';

if( date( 'Y-m-d' ) == $checkDate && date( 'Hi' ) >= $checkTime ) {
    // Do something clever
}

Note the use of Hi as the date format string, which allows for a numerical comparison.

Rob
Took me a while to figure out why you stuck the dummy string "Hi" in there. Then I felt smart.
Matchu
Awesome, however one slight problem. It all works when I use a "hard coded date" which is when a user selects a date, however if I use: date("Y/m/d")which is the default if no date is selected then the match doesn't work. Do I need to do anything to this?
bateman_ap
Don't worry, completly missed the -, I was using / to split the D M Y! many thanks for your help
bateman_ap
Why use Hi and not just H and compare against 21? You don't include seconds, so why minutes?
OIS
More or less arbitrary. I could have worked out 21.00 in Swatch beats and used that as the comparison.
Rob