Php Time

They have: 4 posts

Joined: Nov 2009

Hello

I am currently using the below php code to display the time and date on my webpages.

<?php
date_default_timezone_set
('GMT');
echo
date('l d F Y H:i a');
?>

I have just found out this does not allow for daylight saving time, I did find the following on php.net

I (capital i) Whether or not the date is in daylight saving time 1 if Daylight Saving Time, 0 otherwise.

But I could not find an example of how and where to apply this into the code I am using.

Can someone help please

Regards

Webdoc

pr0gr4mm3r's picture

He has: 1,502 posts

Joined: Sep 2006

Use it like this:

<?php
echo date('I');
?>

They have: 4 posts

Joined: Nov 2009

Hello

In that case would the following be right.

<?php
date_default_timezone_set
('GMT');
echo
date('I l d F Y H:i a');
?>

and where would the 0 or 1 go?

Regards

Webdoc

pr0gr4mm3r's picture

He has: 1,502 posts

Joined: Sep 2006

Not exactly, I have that same code here: http://agstesting.com/date.php

See it returns '1' because my server is in a timezone that is in DST. In your case, you would use it in a conditional statement, like:

<?php
   
if (date('I'))
    {
       
// we are in DST
   
}
    else
    {
       
// we are not in DST
   
}
?>

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.