RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find YYYY-MM-DD HH:MM:SS
Expression
^([0-9]{4})-([0-1][0-9])-([0-3][0-9])\s([0-1][0-9]|[2][0-3]):([0-5][0-9]):([0-5][0-9])$
Description
SQL datetime format tester YYYY-MM-DD HH:MM:SS
Matches
2007-07-01 01:01:01 | 2007-08-04 18:01:01
Non-Matches
2007-07-01 | 2007/07/01 | 2007-08-04 24:00:00 | 2007/07/01 12:12
Author Rating: The rating for this expression. Fehér Zsolt
Source ^([0-9]{4})-([0-1][0-9])-([0-3][0-9])\s([0-1][0-9]|[2][0-3]):([0-5][0-9]):([0-5][0-9])$
Your Rating
Bad Good

Enter New Comment

Title

Name

Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Date regex is wrong
Name: Sam
Date: 6/3/2020 4:36:00 AM
Comment:
works for 2007-19-39 12:12:12


Title: Date regex is wrong
Name: Sam
Date: 6/3/2020 4:35:28 AM
Comment:
works for 2007-19-39 12:12:12


Title: SLIGHTLY better
Name: TESTiculER
Date: 9/22/2011 7:16:08 AM
Comment:
This will not allow > 31 for dd, but WILL still allow February 30th. You could do a look behind for the day and year too, to check for month length/leap year, but its probably not worth it. ^([0-9]{4})-([0-1][0-9])-([0-3]((?<!3)[0-9]|[0-1]))\s([0-1][0-9]|[2][0-3]):([0-5][0-9]):([0-5][0-9])$


Title: June 34th?
Name: TESTiculER
Date: 9/22/2011 7:00:42 AM
Comment:
Careful, his will allow 2007-07-34 01:01:01. The 34th day of June. Need a lookbehind for whether the first digit of a day is a three. Also, allows February 31. Good enough for testing basic shape though.


Copyright © 2001-2025, RegexAdvice.com | ASP.NET Tutorials