What is the best way to compare dates?

  1. How to string? "2012-04-29 23:00:01"
  2. how int? 1335726001
  3. another?
  • 2
    The answer depends on thousands of things :) Where do the dates come from, how are they stored, what exactly is supposed to be done with them. Maybe they don’t need to be compared at all, because it makes sense to use INTERVAL in the database. Or maybe we need to convert them to / from RFC 3339 ... - user6550

2 answers 2

I would store them and compare as int. So, less memory is allocated, and comparison is faster, and, unlike lines, they can easily be converted to any desired format. However, @klopp said very correctly - it strongly depends on what you will do with them.

    I think the time () function is simply not replaceable in this situation, firstly it creates int date value, secondly, you can always translate it into a normal (human) view, as well as calculate the difference between dates, even in negative values. Google - time PHP