Jump to content


Photo

strtotime() function problem


  • Please log in to reply
5 replies to this topic

#1 Chirantha

Chirantha
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 09 March 2006 - 07:29 PM

Hi,

I noticed that I cannot seem to use the strtotime() functions with days before 1970 :(. I know how to make a function to do it but its kida slow with all the 'for' loops. So is there an easy way to do it other than making one without the use of my scipt.

Thank you,
Chirantha

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 09 March 2006 - 08:07 PM

[!--quoteo(post=353350:date=Mar 9 2006, 02:29 PM:name=Chirantha)--][div class=\'quotetop\']QUOTE(Chirantha @ Mar 9 2006, 02:29 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Hi,

I noticed that I cannot seem to use the strtotime() functions with days before 1970 :(. I know how to make a function to do it but its kida slow with all the 'for' loops. So is there an easy way to do it other than making one without the use of my scipt.

Thank you,
Chirantha
[/quote]

the issue is that the built in time and date functions in PHP are based off the UNIX EPOCH (the UNIX timestamp is the number of seconds since this time) which occurred at 12am on Jan 1st, 1970. therefore, the time and date functions are not able to be used on dates before then. if you'll post what you currently have available, we may be able to help you optimize your code.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 k.soule

k.soule
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts
  • LocationIllinois

Posted 10 March 2006 - 01:45 AM

Interestingly enough, strtotime doesn't break when it goes farther back than eve of 1970, it just goes negative. The timestamp of March 09, 1941 is -909338400, if I plug this into date like so:

print date('d-M-y', '-909338400');

it prints out " 09-Mar-41 ". What exactly is breaking that you have trouble with?

#4 Chirantha

Chirantha
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 10 March 2006 - 08:08 AM

Funny Though, When I try strtotime("10 September 1900") returns -1 in php 5 :o.

#5 k.soule

k.soule
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts
  • LocationIllinois

Posted 10 March 2006 - 01:06 PM

Try strtotime("1900-09-10"), I'm on PHP 5, also.

#6 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 10 March 2006 - 01:09 PM

[!--quoteo(post=353603:date=Mar 10 2006, 08:06 AM:name=Kyle Soule)--][div class=\'quotetop\']QUOTE(Kyle Soule @ Mar 10 2006, 08:06 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Try strtotime("1900-09-10"), I'm on PHP 5, also.
[/quote]

this may help answer the problem:
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
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.
[/quote]
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users