So in my database I got a datetime field, filled with e.g. 2012-09-19 11:20:33.
Now I’m trying to fetch the datetime.
$blabla = $something->getDatetime();
After that I create a new DateTime, which represents the time now
$now = new \DateTime("now");
And after that I want to subtract them like this (but it doesn’t work)?
$test1 = strtotime($blabla);
$test2 = strtotime($now);
$diff = $test2 - $test1;
echo $diff;
My aim is to subtract the persisted datetime in the database from the time now…the result should be displayed in seconds…so 2012-09-19 11:22:22 – 2012-09-19 11:20:22 equals 120 (seconds).
I also tried to persist a unix timestamp into my database but unfortunately the field type timestamp doesn’t exist.
If you want the answer displayed in seconds, then just subtract the timestamps:-