How to know how long this createt using compare time php

Hay I want to know how cani check how much time ago this post created by compare times
for exxample
This is the post created time and date 2016-10-10T09:53:25+0000
how can i check how much time ago this post created by compare current time

$now = new DateTime();
$then = new DateTime('2016-10-10T09:53:25+0000');

$diff = $now->diff($then);
1 Like

I want to use this in asia/kolkata timezone

Thanks @Dormilich. How do I use this in the Asia/Kolkata timezone?

exactly the same.

DateTime knows wich timezone you use (otherwise it complains about the missing timezone setting).

when I use 2016-10-10T09:53:25+0000
I am not getting right result
if there is time 5:30pm and post time is 5:20pm
its show me post posted time is 4or5 hour ago
its not current I need thus result 10mint ago

5:20pm is not the same as 2016-10-10T09:53:25+0000

we would need to see how you set the timestamp to compare to see what is the issue.

2016-10-10T09:53:25+0000 this time is Facebook Post time when this post posted ok
and i want to show users how much time ago you post this post

right now this timestamp is about 4h ago no matter where you are.

Please can you explain clearly

best explained with an example:

$now = new DateTime();
$then = new DateTime('2016-10-10T09:53:25+0000');

echo 'diff time: ', $now->diff($then)->format('%H:%I'), 
PHP_EOL, 'local time: ', $now->format('H:i'),
PHP_EOL, 'start time (UTC): ', $then->format('H:i'),
PHP_EOL, 'start time (local): ', $then->setTimezone(new DateTimeZone('Asia/Kolkata'))->format('H:i');

Thanks But Still i am not getting right one

then you either expect the wrong one or use the wrong one. but without code that is impossible to answer.

I am getting this time value from Facebook this is post crated time

as long as you don’t tell us what your code does, we cannot help you further.

You can check this in graph expoloer

nope, I can’t (due to authentication failure)

anyways, the created time is in UTC and the timestamp you posted is about 5 h old now. not sure what you expect to see …

This post i was posted 2 days 2016-10-06T05:35:08+0000
i want to show This Post Time 2days ago

then do that!

the DateInterval object gives you access to the exact difference in days, hours, minutes, etc. but formatting those data is your job as a programmer! depending on how you want it to look you can start with DateInterval’s format() method.