Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

strtotime Alternative?

Status
Not open for further replies.

bdichiara

Programmer
Oct 11, 2006
206
US
I have a function to help find the end of a lease. the problem is it uses the Unix Timestamp (which I hate). Is there an alternate way to do this that doesn't return "December 31, 1969" when using dates beyond 2038?

Code:
function findLeaseEnd($m,$d,$y,$t){
  $term = ($d == 1) ? ($t - 1) : $t;
	
  $newdate = $y."-".$m."-".$d." + ".$term." months";
  $leaseEnd = date("F t, Y",strtotime($newdate));
	
  return $leaseEnd;
}

_______________
_brian.
 
and as i believe i found when sleipnir214 jogged my elbow the other day, the date restrictions have been lifted in php >=5.1.0 (or at least that's how i read the manual although it is slightly ambiguous).
 
bdchiara:
The text in question is on the PHP online manual page for strtotime() (
[tt]Note: The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer.) Additionally, not all platforms support negative timestamps, therefore your date range may be limited to no earlier than the Unix epoch. This means that e.g. dates prior to Jan 1, 1970 will not work on Windows, some Linux distributions, and a few other operating systems. PHP 5.1.0 and newer versions overcome this limitation though.[/tt]

I interpret that note differently from jpadie in that I believe the limitation talked-about is specifically dates before 1970. My support for my interpretation is that on my PHP 5.2.0 machine, the script:

Code:
<?php
print date('Y-m-d H:i:s', strtotime ('2050-05-05 12:23:56'));
?>

outputs:

1969-12-31 18:00:00



Want the best answers? Ask the best questions! TANSTAAFL!
 
that was the ambiguity i was worried about. i was on the verge of testing it. thanks again.
 
jeez, i can't believe i said write.... i'm losing it..

_______________
_brian.
 
can't you just execute the command
Code:
pear install Date --alldeps

i'm on a windows platform but i thought the pear command line was cross-platform.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top