Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The PHP function filemtime returning a negative value or very large value

Tags:

php

filemtime

I am creating a WordPress plugin and can see that on some servers, for certain files, the stat (or filemtime) returning invalid mtime value. In some cases it is a negative value or a very large value (more than 3 billion).

In FTP I can see that the timestamp is correct though.

like image 556
akshat Avatar asked Dec 13 '12 20:12

akshat


1 Answers

When you get Negative numbers in any PHP timestamp its just the amount of seconds before the Unix Epoch and this is not limited to filemtime

Example A

echo strtotime("1950-1-1"); // Outputs  -631155600
                                        ^------- negative value

Example B

Outputting negative values does not mean you can not format it correctly if you try

echo date("Y-m-d",-631155600); // Output  1950-01-01

Lastly

FTP I can see that the timestamp is correct though

Your FTP application is definitely not PHP and has its own internal date system .. its Date System might not use negative values in timestamp

like image 88
Baba Avatar answered Sep 26 '22 10:09

Baba