Jump to content

date has passed function


ldoozer

Recommended Posts

If you can seperate the day, month, and year, convert the month to textual format (example, "august"), then yes, this is very possible, and quite easy.

 

$date = strtotime($day . $month . $year);

$now = strtotime("now");

if($now >= $date) {

  echo "that date has passed";

  } else {

  echo "That date has not yet passed";

  }

 

Should work fine, but remember, you need to have day, month, and year seperate and the month has to be in textual format.

Link to comment
Share on other sites

why not use timestamp and simply go:

 

$now = .....

$to_check = .....

 

if ($to_check > $now ){echo "FUTURE!!!";}

else {echo "ANCIENT HISTORY MAN!!!";}

 

 

 

thats what id do.  you could then store the timestames and do what ever formatting you wanted with it,

 

what your currently doing really restricts formatting

 

 

good luck

Link to comment
Share on other sites

Thanks that give me a good output but using that why wont this work :

$time = strtotime('09/04/2007');
$newdate = date('Y-m-d', $time);

$date = $newdate;
$now = strtotime("now");
if($now >= $date) {
  echo "that date has passed";
  } else {
  echo "That date has not yet passed";
  }

Link to comment
Share on other sites

$time = strtotime('09/04/2007');
$date = date('Y-m-d', $time);

$now = date('Y-m-d', time());
if($now >= $date) {
  echo "that date has passed";
  } else {
  echo "That date has not yet passed";
  }

 

www.php.net/time

Link to comment
Share on other sites

You really should be comparing UNIX timestamps not ASCII strings here:

<?php
$date = strtotime('09/04/2007');

$now = time();
if($date < $now)
  echo "That date has not yet passed";
else
  echo "that date has passed";
?>

 

Ken

Link to comment
Share on other sites

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.