COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### How to detect if daylight savings time are in effect?

• Follow

```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

```>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

```>
> 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

```>> 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

```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

```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

6 Replies
782 Views

Similiar Articles:

7/25/2012 12:38:09 PM