Have you setted the date_default_timezone_set BEFORE the script?
As suggested on the php documentation:
To avoid frustrating confusion I recommend always calling
date_default_timezone_set('UTC') before using strtotime().
Because the UNIX Epoch is always in UTC; you will most likely output
the wrong time if you do not do this.
Cheers
If you did it, maybe can you check what does output, in general, another date?
E.G.:
$listdate = date("Y-m-d",strtotime("now"));
Also, does mktime work for you?
EDIT after comments:
It seems that you're not the only one experiencing such problems with PHP 5.3, in fact, always from the documentation, a user experienced something similar and gave a solution for windows platforms:
Most of the scripts here depend on PHP identifying the correct zone
when one is not set, but that does not always happen.
For example PHP 5.3.3 gives a 'UTC' result for a detected '8.0/no
DST'. Not much help.
So for those of us who for very good reasons really cannot set time
zones in scripts of in .ini files, here is a function for use in a
Windows environment that sets the default time zone to the OS time
zone and returns the detected and set texts.
<?php
function date_system_timezone_set(){
$shell = new COM("WScript.Shell") or die("Requires Windows Scripting Host");
$time_bias = -($shell->RegRead(
"HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control
\\TimeZoneInformation\\Bias"))/60;
$ab = -($shell->RegRead(
"HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control
\\TimeZoneInformation\\ActiveTimeBias"))/60;
$sc = $shell->RegRead(
"HKEY_USERS\\.DEFAULT\\Control Panel\\International\\sCountry");
foreach(timezone_abbreviations_list() as $tza) foreach($tza as $entry){
$country = strtok($entry['timezone_id'],'/');
$locale = strtok('|');
if($country==$sc && $ab==($entry['offset']/60/60) && ($ds = $time_bias!=$ab)==$entry['dst']){
date_default_timezone_set($timezone_identifier = $country."/".$locale);
return sprintf('%.1f',$ab)."/".($ds?'':'no ').'DST'." ".$timezone_identifier;
}
}
return false;
}
?>
Also, looking on googles, after maaaaaaaaaany searchs, I found out many persons saying that in PHP 5+ you MUST define date.timezone in PHP.ini!
From a forum:
date.timezone option in php.ini must be set in PHP 5.3.0+
link to the topi: http://www.silverstripe.org/installing-silverstripe/show/15398?start=8
So, please try to add to your PHP.ini date.timezone!
Other update (always after more comments):
Since your code is working if you parse the date, use a date parser or try this:
<?php
$str = 'Posted: Thu Sep 05 2013 3:40 pm ';
$listdate = preg_replace('/Posted: /','',$str );
$listdate = date('Y-m-d',strtotime($listdate));
echo $listdate;
?>
This echos to me 2013-09-05
If this still doesn't work use datetime or date parsers as suggested here...
Last and FINAL edit:
Tried this code on my crunchbang linux with php 5 and it actually works:
<?php
$str = 'Posted: Thu Sep 05, 2013 3:40 pm ';
$listdate = preg_replace('/Posted: /','',$str );
$date = date_create_from_format('D M j, Y g:i a ', $listdate);
echo date_format($date, 'Y-m-d');
?>