Answer the question
In order to leave comments, you need to log in
Sort by text date in php?
I have data where %CreationDate% is formatted as strings like
[Sun May 01 00:00:00 +0000 2011].
Is there any way to sort the data by date without any special tricks? Maybe there is an easy way to overtake this text string with a date into something else - more digestible for sorting without straining?
Answer the question
In order to leave comments, you need to log in
Personally, I would do this:
* turn the string back into a DateTime object
* use the format("U") method to get the timestamp
* compare the dates by the received value
If the string format is always constant, you have to convert strings to numbers very often, and the execution time is critical, then I would advise you to write your own function “tailored” for this format, and not use the universal strtotime (after writing the function, you should of course compare its performance with strtotime).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question