PHP: Adding hours to timestamp fields while printing the formatted date

So imagine your MySQL is on a shared host and you have time stamps which are automatically inserted in the table. In this case, updating MySQL’s time zone settings is beyond your control. Or even if you can set the time zones, for any records that are in a specific time zone, you can add ¬†hours or minutes to the timestamp you get from the database in the PHP code.

Assuming your record object is $record and the timestamp field¬†is ‘timestamp’, the following code will allow you to add 5 hours to your timestamp and print in the d/m/Y format which you can update in the code below.

echo date('d/m/Y h:i:s A', strtotime($record['timestamp'] . '+5 hours'));

Hope you are going to find this tip useful.

Leave a Reply

Your email address will not be published. Required fields are marked *