I have a script that calculates the number of days since 1/1/00 .
However is there a way to have it give the correct answer when
daylight savings time are in effect? See my code below:
$then = mktime ( 0 , 0, 0, 1,1,'00');
$now = time();
// Comment out for daylight savings time
//$days = ($now - $then + 3600 ) / 86400 - 1;
$days = ($now - $then ) / 86400 - 1;
|
|
0
|
|
|
|
Reply
|
mynonsense (4)
|
12/7/2009 9:01:29 PM |
|
Mr. Nonsense wrote:
> I have a script that calculates the number of days since 1/1/00 .
> However is there a way to have it give the correct answer when
> daylight savings time are in effect? See my code below:
>
>
> $then = mktime ( 0 , 0, 0, 1,1,'00');
> $now = time();
>
> // Comment out for daylight savings time
> //$days = ($now - $then + 3600 ) / 86400 - 1;
> $days = ($now - $then ) / 86400 - 1;
Assuming DST is not in effect on 1/1/00, check to see if DST is in
effect now. If it is, adjust the time by 3600 seconds.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
|
|
0
|
|
|
|
Reply
|
Jerry
|
12/7/2009 10:14:50 PM
|
|
>I have a script that calculates the number of days since 1/1/00 .
There is no year 00. PHP might accept that as an argument to mktime(),
but it's awful as a specification for what the script is supposed to
do.
>However is there a way to have it give the correct answer when
>daylight savings time are in effect? See my code below:
>
>
>$then = mktime ( 0 , 0, 0, 1,1,'00');
>$now = time();
>
>// Comment out for daylight savings time
>//$days = ($now - $then + 3600 ) / 86400 - 1;
>$days = ($now - $then ) / 86400 - 1;
You can use localtime() to figure out if daylight savings time is
in effect for any particular time, using the is_dst value returned.
|
|
0
|
|
|
|
Reply
|
gordonb
|
12/8/2009 3:33:33 AM
|
|
>
> Assuming DST is not in effect on 1/1/00, check to see if DST is in
> effect now.
that is the million dollar question. I checked the documentation but
cannot find any built-in function in PHP to check if DST is in effect
or not .
|
|
0
|
|
|
|
Reply
|
Mr
|
12/8/2009 3:34:15 AM
|
|
>> Assuming DST is not in effect on 1/1/00, check to see if DST is in
>> effect now.
>
>that is the million dollar question. I checked the documentation but
>cannot find any built-in function in PHP to check if DST is in effect
>or not .
localtime()
|
|
0
|
|
|
|
Reply
|
gordon
|
12/8/2009 3:36:40 AM
|
|
Gordon Burditt wrote:
>> I have a script that calculates the number of days since 1/1/00 .
>
> There is no year 00. PHP might accept that as an argument to mktime(),
> but it's awful as a specification for what the script is supposed to
> do.
>
>> However is there a way to have it give the correct answer when
>> daylight savings time are in effect? See my code below:
>>
>>
>> $then = mktime ( 0 , 0, 0, 1,1,'00');
>> $now = time();
>>
>> // Comment out for daylight savings time
>> //$days = ($now - $then + 3600 ) / 86400 - 1;
>> $days = ($now - $then ) / 86400 - 1;
>
> You can use localtime() to figure out if daylight savings time is
> in effect for any particular time, using the is_dst value returned.
>
date('I') will also identify whether DST is in effect or not.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
|
|
0
|
|
|
|
Reply
|
Jerry
|
12/8/2009 4:34:53 AM
|
|
Mr. Nonsense escribi�:
> I have a script that calculates the number of days since 1/1/00 .
> However is there a way to have it give the correct answer when
> daylight savings time are in effect? See my code below:
>
>
> $then = mktime ( 0 , 0, 0, 1,1,'00');
> $now = time();
>
> // Comment out for daylight savings time
> //$days = ($now - $then + 3600 ) / 86400 - 1;
> $days = ($now - $then ) / 86400 - 1;
A quick trick is to create your timestamp at 12:00 rather than 00:00.
(Year zero??)
--
-- http://alvaro.es - �lvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programaci�n web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
|
|
0
|
|
|
|
Reply
|
ISO
|
12/9/2009 12:01:28 PM
|
|
|
6 Replies
782 Views
(page loaded in 0.186 seconds)
|