teshvenk
teshvenk

Reputation: 403

Seconds to Minutes conversion in PHP

I am using below code to convert seconds into minutes:seconds

$dtF = new DateTime("0");
$dtT = new DateTime("500");
$dtF->diff($dtT)->format('%i:%s');

It is working fine in Windows, but not in Linux. I dont know the reason. Experts please help me out of this.

I am getting the following error:

Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string

Upvotes: 0

Views: 72

Answers (1)

John Conde
John Conde

Reputation: 219794

0 and 500 of what? PHP doesn't know. Specify your units of time:

$dtF = new DateTime("0 seconds"); // aka "now"
$dtT = new DateTime("500 seconds");
echo $dtF->diff($dtT)->format('%i:%s');
// 8:20

Demo

Upvotes: 1

Related Questions