I'm attempting to use the PHP DateTime class on a Solaris server with PHP 5.2.6, while testing on my local Windows box running PHP 5.3. Here is the code:
<?php
try {
$dt = new DateTime('2009-10-08');
$dt->setDate(2009,10,8);
print_r($dt);
}catch (Exception $e) {
echo $e->getMessage();
}
On the test server, things work flawlessly, this is what prints:
DateTime Object ( [date] => 2009-10-08 00:00:00 [timezone_type] => 3 [timezone] => America/New_York )
On the server I need to use it on, however, this is what prints:
DateTime Object ( )
Removing the setDate makes no difference whatsoever.
Any ideas why this might be happening?
Thanks!
Edit
Modified the script:
try {
echo '|', date_default_timezone_get(), '|';
date_default_timezone_set('America/New_York');
echo '|', date_default_timezone_get(), '|';
$dt = new DateTime('2009-10-08');
$dt->setDate(2009,10,8);
print_r($dt);
}catch (Exception $e) {
echo $e->getMessage();
}
New output on the server:
|US/Eastern||America/New_York|DateTime Object ( )