I have table with row id, name, created_at and I want to output the created_at row as timestamp time ago in php
Asked
Active
Viewed 36 times
0
-
Please provide enough code so others can better understand or reproduce the problem. – Community May 16 '22 at 00:43
1 Answers
0
replace time()
method with created_at
$date = date("Y-m-d H:i:s", time());
Is this will help you ? Convert time in HH:MM:SS format to seconds only?
... converted to seconds
// example date from db
$created_at = "22-05-15 00:49:59";
$created = strtotime($created_at);
$current = strtotime("now");
$diff = $current - $created;
echo "Diff: " . $diff . " \n";

obeid salem
- 129
- 2
- 13
-
It display date and time but I want it to display in time elapsed like 1 hours ago, 1 day ago, 1 year ago etc – Famoustech May 14 '22 at 21:33
-
ok .. so the method will be: ``current_time - created_at = 1 Hours ago.`` – obeid salem May 14 '22 at 21:36
-
-
yes i know .. so first we need to convert created_at and current time to seconds.. then we do current - created_at = how many seconds.. after that we write a function to convert seconds to minutes & hours & days & months ... – obeid salem May 14 '22 at 21:44
-
-
check updated answer .. and use created_at to be close to seconds ,, to check if its working then we can write method to convert these seconds into string – obeid salem May 14 '22 at 21:53
-