FRIHOST • FORUMS • SEARCH • FAQ • TOS • BLOGS • COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Future or Past





DanielXP
I need a script that can tell me if the date is in the future or in the past.

My date varibles are as follows.

$day = day (eg. 11)
$month = month (eg. 4)
$year = year (eg. 2008)

If so then the varible

$status Would then equal past

Or

$day = day (eg. 1)
$month = month (eg. 10)
$year = year (eg. 20190)

$status Would then equal future


Thanks, I have already had a go and failed Sad

Daniel
rvec
Code:
$day = date(j);
$month = date(n);
$year = date(o);

I think you can get it from there.
DanielXP
i have tryed that i had like loads of if's for like if the month is bigger but the year is less or month is less and so is the year and as well as loads of them you have the day
sonam
Try this:
Code:
<?php
$day = date(j); // current server day
$month = date(n); // current server month
$year = date(o); // current server year

$day2 = 29; // some imput for day
$month2 = 4; // some imput for month
$year2 = 2008; // some imput for year

if($year2 > $year) {
   $msg = "You are in the future!";
} elseif ($year2 < $year) {
   $msg = "You are in the past!";
} else {
   if($month2 > $month) {
      $msg = "You are in the future!";
   } elseif ($month2 < $month) {
      $msg = "You are in the past!";
   } else {
      if($day2 > $day) {
         $msg = "You are in the future!";
      } elseif ($day2 < $day) {
         $msg = "You are in the past!";
      } else {
         $msg = "You are in the NOW!";
      }
   }
}
echo $msg;
?>


Sonam
DanielXP
THanks for you reply.

I found a site on google and edited it so i could get it to work for me.

Code:
function dateworkout($date) {
$dateN = explode("/", $date);
$dateString = $dateN[2] . "-" . $dateN[1] . "-" . $dateN[0];
if(strtotime($dateString) > time()) {
$status = "future";
}else if(date("Y-n-j", time()) == $dateString) {
$status = "now";
}else if(strtotime($dateString) < time()) {
$status = "past";
}
return $status;
}


So
Code:
<?
echo dateworkout("11/4/1991");
?>


would echo "past"

Thanks for your help sonam Smile
Related topics
Is there an infinite past?
Time
Religion vs. Relationship
The Last Movie You Saw?
In the midst of this get-together in a common area
the future of the past tense
Time travel is possible but only to future not to the past
Forecasting Future Services
Time Travel: Is it Possible?
The Tech Tree! Post any interesting media about future tech!
Future democrasies??
Asia’s Future and the Financial Crisis
Is time travel possible in future
The future of IT
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.