4

I would like to add the last modified date to the index page , the below code shows the 31/12/1969 is the last modified date.

echo date("d/m/Y",filemtime("index.php"));
1
  • 2
    Please show var_dump(filemtime("index.php")); - suspect you'll find it says bool(false). Make sure that index.php is the correct relative path to the file you are look for the modified time of. Commented Jul 30, 2012 at 9:38

2 Answers 2

4

I guess the path is wrong. At last on your development system you should increase the error settings.

In case of an erro filemtime() returns false, what what gets casted into 0 by the date()-call.

You should refer your files on the filesystem using (pseudo-)absolute paths.

__DIR__ . '/path/to/index.php';
Sign up to request clarification or add additional context in comments.

Comments

0

My guess is filemtime is not finding your file. filemtime will return 0, or something that equates to 0 like FALSE, and then applying date on time 0 will return 0 seconds since the epoch (1st Jan 1970).

Looks like that's what you're getting. I'm also guessing you're using PHP <= 5.1.

2 Comments

my php version is 5.3.. i given absolute path but till t shows an error
@BalluRocks Probably something to do with PHP returning negative numbers for pre-epoch times. I'd suggest DaveRandom's approach and dump out the result of filemtime and see what it says. If it's false, then it's still a path issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.