Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php - One Hour Earlier Than Given Datetime

Tags:

php

datetime

I'm having a problem here..

Supposed I have this kind of datetime.


$date = strtotime($date);

I need this to be converted into the Unix-timestamp format but one hour earlier..I tried


$date = strtotime($date-86400)

, but seemed to me it is wrong. It returned 0 when I sneaked into the table.

What is the appropriate way to achieve this?

Thanks.

like image 773
foxns7 Avatar asked Feb 27 '12 04:02

foxns7


1 Answers

You could do:


$testDateStr = strtotime($date);
$finalDate = date("Y-m-d H:i:s", strtotime("-1 hour", $testDateStr));

Hope it helps

like image 200
Sudhir Bastakoti Avatar answered Sep 22 '22 06:09

Sudhir Bastakoti