Connecting Tech Pros Worldwide Help | Site Map

Number of days in 1/1/2000

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 11th, 2005, 03:35 PM
el_roachmeister@yahoo.com
Guest
 
Posts: n/a
Default Number of days in 1/1/2000

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.


  #2  
Old November 11th, 2005, 03:35 PM
bradb
Guest
 
Posts: n/a
Default 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.

  #3  
Old November 11th, 2005, 03:45 PM
Oli Filth
Guest
 
Posts: n/a
Default 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
  #4  
Old November 11th, 2005, 03:45 PM
Erwin Moller
Guest
 
Posts: n/a
Default 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
  #5  
Old November 11th, 2005, 04:15 PM
Peter Fox
Guest
 
Posts: n/a
Default 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>
  #6  
Old November 11th, 2005, 04:35 PM
JDS
Guest
 
Posts: n/a
Default 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/

  #7  
Old November 11th, 2005, 06:05 PM
el_roachmeister@yahoo.com
Guest
 
Posts: n/a
Default 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

  #8  
Old November 11th, 2005, 06:25 PM
Oli Filth
Guest
 
Posts: n/a
Default 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
  #9  
Old November 11th, 2005, 07:55 PM
Toby Inkster
Guest
 
Posts: n/a
Default 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

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.