Sorting Date/Time In PHP

2 replies
Hey Warriors,

I'm looking for a way to sort dates and times with PHP.

Currently I'm using timestamps, but I'm really having a hard time wrapping my head around how I'm trying to do it.

What I'm looking to do is check for dates between (date a) and (date b) and add 1 to a variable every time one is found.

In theory this is easy, but I'm having a hard time with this today for some reason.

So, how would you recommend sorting yyyy-mm-dd hh:mm:ss? Of course, i'm open to using another format, if it's easier to sort through.
#date or time #php #sorting
  • Profile picture of the author Robert Plank
    Chris,

    Store the dates using the numeric date representation... only worry about converting to yyyy-mm-dd when you display the dates to viewers.
    {{ DiscussionBoard.errors[1227307].message }}
    • Profile picture of the author Pro24
      If you strip yyyy-mm-dd mm:ss to this: YYYYmmddmmSS then you can use the built in php sorting, compare functions.
      Just make sure you use the date field with leading 0!, otherwise it will not work. For example, in Day use the "d" as that represents a numerical value of the day with leading 0, from 0-31.
      {{ DiscussionBoard.errors[1228306].message }}

Trending Topics