Home » Php » PHP date("I") for a future or past date

PHP date("I") for a future or past date

Posted by: admin July 12, 2020 Leave a comment

Questions:

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?

How to&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