Subtract 6 hours from a timestamp using PHP

I have this code to display the date and time from a database. How do I change it to subtract 6 hours from a timestamp.

date('m-d g:Ga', strtotime($row['time_stamp']))
+5
source share
3 answers

UNIX timestamps are seconds from the era. Just subtract the number of seconds in six hours:

date('m-d g:Ga', strtotime($row['time_stamp'])-21600)

You can also use strtotimeagain:

date('m-d g:Ga', strtotime('-6 hours', strtotime($row['time_stamp'])))
+14
source

Since in MySQL you can do MySQL for you:

SELECT DATE_FORMAT('...', DATE_SUB(time_stamp, INTERVAL 6 HOUR)) ...

MySQL, PHP strtotime(), , . strtotime , .

+4

$ vindate = date ('H: i: s', strtotime ($ row ['ms_attend_time']) + 19800); echo $ vindate;

0
source

All Articles