Skip to content

Instantly share code, notes, and snippets.

@mcloide

mcloide/comparison.php

Last active Apr 11, 2016
Embed
What would you like to do?
PHP Datetime comparison unexpected behavior
<?php
foreach (['EST', 'EDT', 'CST', 'CDT', 'PST', 'PDT'] as $tz) {
echo "---- TZ: $tz ---- \n";
$now = new DateTime('@' . (new DateTime('11:30 AM EST'))->getTimeStamp());
$earlier = new DateTime('7 AM', new DateTimeZone($tz));
echo $now->format('r') . "\n";
echo $earlier->format('r') . "\n";
$mod = $now->setTimeZone(new DateTimeZone($tz));
echo $now->format('r') . "\n";
echo $earlier->format('r') . "\n";
echo (int)($earlier < $now) . "\n";
echo $now->getTimestamp() . "\n";
echo (int)($earlier < $now) . "\n";
echo "------------------\n\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.