-2

I have two date time, date1 = '2012/10/18 14:12:12' date2 = '2012/10/18 14:20:12'

and the date2-date1 is 8 in minute. I want to get the diffrent in minutes.

But if the date2 > date1

date1 = '2012/10/18 14:02:12' date2 = '2012/10/18 14:10:12'

Then I want to get the -8 result. How can I do this in php?

RJaniii
  • 25
  • 6

1 Answers1

-1

Look into the Datetime class.

You will need Datetime::createFromFormat() (to convert your strings into Datetime objects) and Datetime::diff() (which will give you the difference between any two Datetimes, divided into years, months, days etc.).

Jakub Wasilewski
  • 2,916
  • 22
  • 27