Connecting Tech Pros Worldwide Forums | Help | Site Map

Number of days in 1/1/2000

el_roachmeister@yahoo.com
Guest
 
Posts: n/a
#1: Nov 11 '05
I am looking for a script that can report the number of days since
2000. It should handle leap years but I am not worried about accuracy
to the hour/minute or seconds. I am writing a calendar program and need
a reference point to base all my dates from. So I picked 1/1/2000.


bradb
Guest
 
Posts: n/a
#2: Nov 11 '05

re: Number of days in 1/1/2000


There are many calendar functions built into PHP
http://us3.php.net/manual/en/ref.calendar.php
I would suggest you look into those, as you may find a much better way
to do what you want.

Oli Filth
Guest
 
Posts: n/a
#3: Nov 11 '05

re: Number of days in 1/1/2000


el_roachmeister@yahoo.com said the following on 11/11/2005 16:24:[color=blue]
> I am looking for a script that can report the number of days since
> 2000. It should handle leap years but I am not worried about accuracy
> to the hour/minute or seconds. I am writing a calendar program and need
> a reference point to base all my dates from. So I picked 1/1/2000.
>[/color]

http://www.php.net/mktime

Then divide by 86400 ( = 24 * 60 * 60)

--
Oli
Erwin Moller
Guest
 
Posts: n/a
#4: Nov 11 '05

re: Number of days in 1/1/2000


el_roachmeister@yahoo.com wrote:
[color=blue]
> I am looking for a script that can report the number of days since
> 2000. It should handle leap years but I am not worried about accuracy
> to the hour/minute or seconds. I am writing a calendar program and need
> a reference point to base all my dates from. So I picked 1/1/2000.[/color]

Hi,

I think the most simple way is using Unix timestamps

(from http://nl2.php.net/manual/en/function.time.php)

*******************************
time() -> Return current Unix timestamp
Returns the current time measured in the number of seconds since the Unix
Epoch (January 1 1970 00:00:00 GMT).
*******************************

So code something like this:
1) Get the Unixtime for 1/1/2000 (you can calculate that only one time, and
use the number from then on hardcoded if you want)

2) Get the Unixtime for now: use the function time()

3) get the difference

4) divide it by the number of seconds in a day.

You will always get a 'dayfraction' this way, and have to do some rounding.

How you do the rounding is up to your taste of course.
(Eg, if the difference between now and 1/1/2000 is X and a half day, do you
want to work with X or X+1 ?)

Hope this helps. :-)

Good luck!

Regards,
Erwin Moller
Peter Fox
Guest
 
Posts: n/a
#5: Nov 11 '05

re: Number of days in 1/1/2000


Following on from bradb's message. . .[color=blue]
>There are many calendar functions built into PHP
>http://us3.php.net/manual/en/ref.calendar.php
>I would suggest you look into those, as you may find a much better way
>to do what you want.
>[/color]

Come off it! You'll be telling us next there is an extensive manual
available in various handy formats for instant download from the web
next.

Eee I remember when I were a lad when we had nobut beads and bits of
coloured glass and feathers handed down from father to son. And all
we'd got to code with was pneumatic riveter. All by the light of a
guttering candle stuck in a heap of mud - in hexadecimal of course.
There we were, fighting in the trenches by day, programming using with
broken matchsticks and blood soaked bandages during the night - all on
5d a day. Lah-de-dah computer geeks of today don't know they're even
born. WE didn't even have computers - but we still managed to program
even though we had to sell our own snot to pay for the fish bones to
feed the owls.

--
PETER FOX Not the same since the e-commerce business came to a .
peterfox@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>
JDS
Guest
 
Posts: n/a
#6: Nov 11 '05

re: Number of days in 1/1/2000


On Fri, 11 Nov 2005 17:06:55 +0000, Peter Fox wrote:
[color=blue]
> WE didn't even have computers - but we still managed to program
> even though we had to sell our own snot to pay for the fish bones to
> feed the owls.[/color]

Too much coffee today? Not enough? MP festival on the telly?

--
JDS | jeffrey@example.invalid
| http://www.newtnotes.com
DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

el_roachmeister@yahoo.com
Guest
 
Posts: n/a
#7: Nov 11 '05

re: Number of days in 1/1/2000


thanks for the replies, here's what I did. Is there any situation where
this would not give the right answer?


function get_current_day() {

$then = mktime ( 0 , 0, 0, 1,1,'00');
$now = time();

$days = ($now - $then ) / 86400 - 1;

return (int) $days;

} // end function

Oli Filth
Guest
 
Posts: n/a
#8: Nov 11 '05

re: Number of days in 1/1/2000


el_roachmeister@yahoo.com said the following on 11/11/2005 18:56:[color=blue]
> thanks for the replies, here's what I did. Is there any situation where
> this would not give the right answer?
>
>
> function get_current_day() {
>
> $then = mktime ( 0 , 0, 0, 1,1,'00');
> $now = time();
>
> $days = ($now - $then ) / 86400 - 1;
>
> return (int) $days;
>
> } // end function
>[/color]

Not sure about the -1. If today was the 2nd Jan 2000, for instance, then
your answer would be 0, but you presumably would want 1.

--
Oli
Toby Inkster
Guest
 
Posts: n/a
#9: Nov 11 '05

re: Number of days in 1/1/2000


el_roachmeister wrote:
[color=blue]
> I am looking for a script that can report the number of days since
> 2000.[/color]

<?php
$start = strtotime("1 Jan 2000");
$finish = strtotime("now");
$diff = $finish - $start;
$days = (int)($diff / 86400);
print $days;
?>

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Closed Thread