Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_php thread: How to calculate the days between two set dates??


Message #1 by guru@i... on Fri, 6 Jul 2001 21:17:51
> I like mktime because you can specify the time also.  A 
> little bit more flexibility, but either way is basically the 
> same concept.
> 

To be honest, I might use mktime as well but more a superstitious thing
(used it in C a lot).

I didn't include time for simplicity but strtotime() does that as well:

$timestamp1 = mktime(10,11,12,7,11,2001);
$timestamp2 = strtotime("07/11/2001 10:11:12am");
echo $timestamp1 . " = " .  $timestamp2 . "<br>";

You can even pump in strtotime("today") and it spits out time().

These are cool too:

echo "Tomorrow: " . (time() + 86400) . " = " .  strtotime ("tomorrow") .
"<br>";
echo "Next week: " . (time() + 604800) . " = " .  strtotime ("next
week") . "<br>";

I primarily use PHP in Unix so can't vouch for MS (NT etc.) but I would
think it would return the same.

B.Page

> Adam Lang
> Systems Engineer
> Rutgers Casualty Insurance Company http://www.rutgersinsurance.com
> ----- Original Message -----
> From: "Bob Page" <bpage@w...>
> To: "professional php" <pro_php@p...>
> Sent: Monday, July 09, 2001 5:34 PM
> Subject: [pro_php] RE: How to calculate the days between two 
> set dates??
> 
> 
> > I agree. I would do it like this:
> >
> > $today = time();                   //Today's timestamp.
> > $today_str = date("m/d/Y", $today);//Make a string out of it.
> > $future_str = "07/16/2001";        //Some arbitrary future date.
> > $future = strtotime($future_str);  //Find timestamp for future date.


  Return to Index