Why do I get 31 Dec 1969 as my last modified filename using filemtime in php?
datetime, function, php
Solution
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 ?
Problem
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 ?