I am newbie to php and so please do not mind me asking this question but am really getting confused as to why filemtime(filename.txt)
gives me as 31 Dec 1969 as my last modified time ?
views:
224answers:
4January 1, 1970 0:00 is the start of the Unix epoch. Thus, a timestamp of 0, which is the result of a failed filemtime operation, together with (probably) a DST issue, is December 31, 1969. You need to fix your filemtime operation, for example (if your example is not just pseudo-code) by adding quotes to the filename:
filemtime ("filename.txt");
This probably means your file was not found, either :
- because it doesn't exist
- or because it's not in the currect directory
- or because you didn't quote its name -- you didn't ^^
1st january 1970 is the date of time "zero" ; and filemtime
returns false
when there is a problem...
So, 31 Dec 1969 is the date/time of zero... According to your locale, I suppose ; I myself, with this code :
$filemtime = filemtime(filename.txt);
$formated = date('Y-m-d H:i:s', $filemtime);
var_dump($filemtime, $formated);
get this output :
boolean false
string '1970-01-01 01:00:00' (length=19)
false because the file doesnt' exist, and 1970-01-01
at 01:00
because of my locale (I'm in France, at UTC+1 hour)
And note I also get a couple of notices and warnings :
Notice: Use of undefined constant filename - assumed 'filename'
Notice: Use of undefined constant txt - assumed 'txt'
Warning: filemtime() [function.filemtime]: stat failed for filenametxt
Do you have any of those ?
If no : are error_reporting
and/or display_errors
enabled ?
You can't use
$t = filemtime(filename.txt);
At a minimum, use something like
$t = filemtime("filename.txt");