Check DST in PHP

User
Check dst time in php
Assistant
To check if Daylight Saving Time (DST) is currently in effect using PHP, you can use the `date()` function along with the `'I'` format character:

if (date('I')) {
    echo "Daylight Saving Time is currently in effect.";
} else {
    echo "Daylight Saving Time is not in effect.";
}

### Explanation:
– `date('I')` returns:
– `1` if DST is in effect.
– `0` if DST is not in effect.

### Optional: Check for a specific timezone
If you want to check DST status for a specific timezone, you can do this:

$timezone = new DateTimeZone('America/New_York'); // Change to your desired timezone
$datetime = new DateTime('now', $timezone);

if ($datetime->format('I')) {
    echo "DST is in effect in " . $timezone->getName();
} else {
    echo "DST is not in effect in " . $timezone->getName();
}

Let me know if you want to log it, use it in logic, or display it on a webpage.

Leave a Comment

Your email address will not be published. Required fields are marked *