Calling mktime before 1/1/1960

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
techlinks
Forum Newbie
Posts: 18
Joined: Sun Dec 29, 2002 4:00 am

Calling mktime before 1/1/1960

Post by techlinks »

Hi again:

I need to calculate the number of minutes between the current time and
January 1, 1601. Can someone suggest an optimal way to do this in PHP? I can't do a mktime on the date 1/1/1601 because it complains it can't go back further than 1/1/1970. Thanks in advance
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

mins in hour = 60
mins in day = 60*24
mins in year = 60*24*365
mins in leap year = 60*24*366
years since 1601 = 403
leap years = 100
days since 1 jan = ...

Etc, and just work your way back. Im sure you can make a function so it will tell you for any date you imput, its just a process of working it out.
techlinks
Forum Newbie
Posts: 18
Joined: Sun Dec 29, 2002 4:00 am

Post by techlinks »

thanks for the prompt response. this may be a silly question but how did you compute:

mins in leap year = 60*24*366

and

leap years = 100

I don't quite understand.

Thanks
crookedgoomba
Forum Newbie
Posts: 4
Joined: Fri May 28, 2004 2:38 am

Post by crookedgoomba »

divide the number of years since 1601 by 4... considering there are leap years every 4 years
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

crookedgoomba wrote:divide the number of years since 1601 by 4... considering there are leap years every 4 years
Ya, leap years every 4 years, except when the year is divisible by 100, except when the year is divisible by 400 (then it's a leap year as well).
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

or you could just use mins in year = 60*24*365.25 and leave it at that (i think)
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Sorry to get technical (and I'm sure this is over the top for what you want) but if you want to be really accurate you have to take into account leap seconds as well.
Leap seconds occur because the effect of the tides on the Earth's rotation slows it down, putting our day/night timings out slightly.
There is much more information here.
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

awesome! i heard on npr that they think the earths spin is slowing down
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Nice, i never knew about leap seconds. Thanks for the info grim...
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

It's kind of my job to know about time - I work for a Time & Attendance company, and our software has to be very accurate.
Post Reply