Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   Sorting Date/Time In PHP (https://www.warriorforum.com/programming/128941-sorting-date-time-php.html)

Chris Ramsey 28th September 2009 11:22 AM

Sorting Date/Time In PHP
 
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.

Robert Plank 28th September 2009 01:44 PM

Re: Sorting Date/Time In PHP
 
Chris,

Store the dates using the numeric date representation... only worry about converting to yyyy-mm-dd when you display the dates to viewers.

Pro24 28th September 2009 08:00 PM

Re: Sorting Date/Time In PHP
 
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.


All times are GMT -6. The time now is 02:57 PM.