0

I want to find date difference between two dates in PHP 5.2

I am not sure if date_diff can be used. The PHP manual says (PHP 5 >= 5.3.0)

I do not understand what this means. Does it mean it is available only in PHP 5, beginning from version 5.3.0?

I wanted to use the solution mentioned in this answer, however if date_diff does not work in 5.2, can anyone help me with what else I can use?

Community
  • 1
  • 1
Undefined Variable
  • 4,196
  • 10
  • 40
  • 69
  • 3
    A related question is why are you still running PHP 5.2? That is very old... PHP 5.6 was just released the other day - you should upgrade. – Laurence Aug 30 '14 at 13:09
  • what error does it give? – undefined_variable Aug 30 '14 at 13:10
  • 1
    @TheShiftExchange : Moreover, since PHP 5.6 has been released PHP 5.4 has only security fix for a year. So it should be a good idea to upgrade PHP. – Debflav Aug 30 '14 at 13:11
  • @TheShiftExchange - Most people forget that the programmers writing code has little control over the server versions in which it runs due to a million reasons. In my case it is a partner company's server where we need to deploy code. It has many other legacy applications running and they are not in a position to upgrade until they have ported everything off. I am sure most people are aware how obsolete these versions are, but it is not as straightforward as just upgrading. In the real world not everything can be as easily fixed. – Undefined Variable Aug 30 '14 at 13:12
  • Also, I checked the answers in the question to which mine was marked as a duplicate - however none of them really answers it. I do not think writing a whole new class is required to do a simple date diff in PHP 5.2, as the answers in that question suggests. – Undefined Variable Aug 30 '14 at 13:15
  • To answer your question - PHP 5>=5.3 means you need "PHP5" and version 5.3 or greater – Laurence Aug 30 '14 at 13:16
  • @TheShiftExchange - thank you for that piece of information. – Undefined Variable Aug 30 '14 at 13:17
  • You could use `strtotime` and do `$diff = strtotime($date1) - strtotime($date2);`. That will give you the difference in dates in seconds. http://php.net/manual/en/function.strtotime.php – Laurence Aug 30 '14 at 13:17

0 Answers0