Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP date("I") for a future or past date [closed]

Tags:

date

php

The PHP date("I") returns either a 0 or 1 depending on if the current date is in daylight savings. However, i need this exact function to return a 0 or 1 for a specified date and time in the future or past.

Any ideas how this can be achieved?

like image 667
Ahmed Avatar asked Jan 20 '13 09:01

Ahmed


1 Answers

Just pass the timestamp of the future date like this:

is_daylight_saving = date("I", future_timestamp);

See PHP date() documentation

****** EDIT:******

To properly get the daylight saving information you need to make sure that your default locale is set to a country using daylight saving. The list of countries using daylight savings can be found here.

To change the default time zone use date_default_timezone() as follows:

date_default_timezone_set('Europe/Rome'); // Italy uses daylight saving
echo date("I", 1366456706); // will return 1

date_default_timezone_set('America/Argentina/Buenos_Aires'); // Argentina doesn't use daylight saving
echo date("I", 1366456706);  // will return 0
like image 73
Tomas Camin Avatar answered Sep 21 '22 14:09

Tomas Camin