PHP DateTime Regex

Posted by CogitoErgoSum on Stack Overflow See other posts from Stack Overflow or by CogitoErgoSum
Published on 2010-05-11T14:29:45Z Indexed on 2010/05/11 14:34 UTC
Read the original article Hit count: 553

Filed under:
|
|

Hey, long story short I have inherited some terrible code. As a result a string comparison is buggy when comparing dates due to the format of the date. I am trying to convert the date to a valid DateFormat syntax so I can run a proper comparison.

These are some samples of the current format:

12/01/10 at 8:00PM

12/31/10 at 12:00PM

12/10/09 at 5:00AM

and so forth. I'd like to convert this to a YYYYMMDDHHMM format i.e 201012012000 for comparison purposes. If anyone can give me a quick regex snippet to do this that'd be appreciated as right now i'm hitting a brick wall for a regex. I can do it by exploding the string over several times etc but I'd rather do it in a more efficient manner.

Thanks!

© Stack Overflow or respective owner

Related posts about php

Related posts about date