Jump to content


Photo

Problems handling really old dates in PHP


  • Please log in to reply
4 replies to this topic

#1 theOlster

theOlster
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 26 September 2006 - 12:32 PM

Hi - I'm currently writing a family tree website and are having problems with really old dates. 

The following code:$return = date("l d F Y", mktime(0, 0, 0, 1, 1, 1234));
echo "$return";

Returns:

Thursday 01 January 1970

Any ideas?

#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 26 September 2006 - 12:44 PM

As far as I know, the mktime() function gives you seconds from the epoch, which on your system is 01/01/1970 so it won't go any earlier than this without some calculation somewhere.

Have you done a search on these forums?  I just did a few searches and came up with a few really useful results... Here's one for a start

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 26 September 2006 - 12:50 PM

There is a class called adodb. You call on it in your script and it will handle old dates. Try googling it or I will post link when I find it.

#4 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 26 September 2006 - 12:54 PM

OK here is the file. I hope I can do this whithout getting in trouble if Iam not suppose to I am sorry and you may just delete this.

Use it like so

<?php
require('includes/adodb-time.inc.php');

$startdate = adodb_date("d-M-Y", adodb_mktime(0,0,0,1,1,1869));
?>

Ray

[attachment deleted by admin]

#5 theOlster

theOlster
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 26 September 2006 - 01:06 PM

Thanks Guys for all your help...
More info can be found on ADOdb here: http://phplens.com/p...re/node/view/16.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users