how to convert Integer values into timestamp format?

Issue

I have an Integer column "duration_temp" that have values represent the duration in minutes, I want to copy those values in another column "duration" of type timestamp, I’m having the problem of how to convert those Int minutes into timestamps format, for example:
if a value in Int is set to 4 then I should convert it to yyyy-mm-dd 00:04:00.
is there a function that can do that or close from doing that?any suggestion would be appreciate it.

Solution

If you have a duration in minutes. You could use DateInterval like this.

$yourDate = new DateTime('2021-01-01 00:00:00');
$durationInMinutes = 4;

$interval = new DateInterval("PT{$durationInMinutes}M");
$yourDate->add($interval);

echo $yourDate->format('Y-m-d H:i:s');

https://www.php.net/manual/en/dateinterval.construct.php

Answered By – Hendrik

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published