0

I want to create a simple preg_match to ensure a series of string values are in the following structure :

20191231T16:10:10

So the first are 4 numbers (to represent the year), the next 2 numbers are the month (represented in 01-12 format) & the last 2 numbers are the days (representing in 01-31) along with the 'T' (spacer), the hours (between 00-23), minutes & seconds (between 00-59)

I have the following regex but it doesn't quite work fully.

https://www.phpliveregex.com/p/p0U

^[0-9]{4}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])[A-Za-z](0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])$(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])$

Zabs
  • 13,852
  • 45
  • 173
  • 297
  • Datetime::createfrom format – splash58 Aug 22 '18 at 09:40
  • Read comments to my answer there - https://stackoverflow.com/questions/51896900/php-parse-date-column-from-excel-sheet-csv/51896940?noredirect=1#comment90835943_51896940 – splash58 Aug 22 '18 at 09:41
  • You need to find them in some text or something or do you have them already and just want to check if they are valid ? – AymDev Aug 22 '18 at 09:42

0 Answers0