Jump to content

Recommended Posts

Hi,

 

I have the date like this Friday 26 June 2009 how can I create a if statment to check if that time is the present or in the past

 

Thanks

 

Checks if $day matches the current day.  Something like this:

 

$day = "Monday 29 June 2009";
$now = date("l j F Y");
echo ($day==$now) ? "today" : "not today";

?>

The above solution is good if you want to determine if the input date is the current date, but not to determine if it is a past date since it may also be a future date.  You can use strtotime to extract a timestamp from the input date and then compare the timestamps of the input date and the current date.  Here is a simple solution:

 

$new_date = strtotime('Friday 26 June 2009');
$current_date = strtotime(date('l j F Y'));
if($new_date < $current_date)
    echo 'input date is a previous date';
elseif($new_date > $current_date)
    echo 'input date is a future date';
elseif($new_date == $current_date)
    echo "input date is today's date";

how can I create a if statment to check if that time is the present or in the past

 

He only specified present or past.  So I think it's safe to speculate that he doesn't allow users to choose a date in the future, but if he does, then good point.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.