I’m setting up PHP’s if-modified-since header on our webpages. I can detect if a php file has been saved and then properly set the header using PHP’s filetime() and date() functions. However I also need to properly set the header when information in the database that gets displayed on the php page changes.
For the file being changed I use PHP’s date() function like so:
date("r", $file_mod)
However when I use it on what I get from querying a MySQL datetime field, I always get the following response where the date, time, year, and month are wrong:
Wed, 31 Dec 1969 18:33:30 -0600
What is the proper way to convert from MySQL’s datetime to RFC 2822, or at least how do I convert to a format to put into PHP’s date() function to get the correct response?
1 Answer