- The first Regular Expression Library on the Web!

Please support RegExLib Sponsors


Regular Expression Details

Title Test Find Pattern Title
This regex will match SQL Server datetime values, allowing date only, allowing zero padded digits in month, day and hour, and will match leap years from 1901 up until 2099.
2/29/2004 | 04/01/2003 10:01:23 am | 03-20-1999
2/29/2003 | 13/30/2001 10:05:00 pm | 12/32/2003
Author Rating: Not yet rated. Sung Lee
Source I took Scott Watermasysk's datetime regex, fixed bugs, added leap year logic
Your Rating
Bad Good

Enter New 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: This reg exp is not working with javascript
Name: Ramakrishna
Date: 9/27/2004 10:35:28 PM
I tried to use this with javascript. but it has some problem .

Title: I fixed an bug
Name: Sung Lee
Date: 11/3/2003 1:33:36 PM
It used to accept 11/31/xxxx as a valid date. I'll fix the ANSI format expression as well. Search for it if that's what you're looking for, don't use the one from my "ANSI format" message above.

Title: ANSI format
Name: Sung Lee
Date: 9/16/2003 5:41:57 PM
This one should be in ANSI format, same limitations as above: ^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13578])|(1[0-2]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]?((((0?[13578])|(1[0-2]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\s(((0?[1-9])|(1[0-2]))\:([0-5][0-9])((\s)|(\:([0-5][0-9])\s))([AM|PM|am|pm]{2,2})))?$

Title: True SQL Server ANSI Format ?
Name: Legion Steve
Date: 9/16/2003 6:53:12 AM
This works great, but the datetime is not in the "true" ANSI SQL Server Format of YYYY-MM-DD. Would it be possible to modify this to work that way? Thanks!

Copyright © 2001-2018, | ASP.NET Tutorials