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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
^([0]\d|[1][0-2])\/([0-2]\d|[3][0-1])\/([2][01]|[1][6-9])\d{2}(\s([0-1]\d|[2][0-3])(\:[0-5]\d){1,2})?$
Description
This is a regular expression to validate a date string in "MM/DD/YYYY" format, a date time string in "MM/DD/YYYY HH:MM" or a date time string in "MM/DD/YYYY HH:MM:SS" format. It can validate date from 1600 to 2199.
Matches
12/30/2002 | 01/12/1998 13:30 | 01/28/2002 22:35:00
Non-Matches
13/30/2002 | 01/12/1998 24:30 | 01/28/2002 22:35:64
Author Rating: The rating for this expression. Spring Zhang
Source
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: Need date time format for given expression
Name: Ritesh
Date: 8/16/2013 5:25:15 AM
Comment:
2013-08-14T20:00:10.953+05:30 i need format for above expression. It show 2013-08-14 20:00


Title: simply modify for italian date format (DD/MM/YYYY)
Name: Andrea Zamboni
Date: 3/16/2010 2:56:53 AM
Comment:
^([0-2]\d|[3][0-1])\/([0]\d|[1][0-2])\/([2][01]|[1][6-9])\d{2}(\s([0-1]\d|[2][0-3])(\:[0-5]\d){1,2})?$


Title: simply modify for italian date format (DD/MM/YYYY)
Name: Andrea Zamboni
Date: 3/16/2010 2:56:42 AM
Comment:
^([0-2]\d|[3][0-1])\/([0]\d|[1][0-2])\/([2][01]|[1][6-9])\d{2}(\s([0-1]\d|[2][0-3])(\:[0-5]\d){1,2})?$


Title: 2 Digit Years
Name: Will
Date: 8/24/2009 10:51:44 AM
Comment:
Doesnt match 2 digit years, eg 98 or 02


Title: A Swedish date variant
Name: Jorgen Bengtsson
Date: 9/6/2006 5:45:15 AM
Comment:
I changed it some to handle dates in the Swedish format and removed the year limit. Thanks Sping Zhang for the base pattern. ^([12])\d{3}\-([0][1-9]|[1][12])\-([0][1-9]|[1-2][0-9]|[3][0-1])(\s([0-1]\d|[2][0-3])(\:[0-5]\d){1,2})?$


Title: works great, except
Name: Jared Livingston
Date: 7/12/2004 2:03:04 PM
Comment:
Since the date that I am validating is auto-generated, the leading 0 is left off of months and/or days that are represented by a single digit. These are not validated properly using the above expression. I think this will handle it, though: ^([0]?\d|[1][0-2])\/([0-2]?\d|[3][0-1])\/([2][01]|[1][6-9])\d{2}(\s([0-1]\d|[2][0-3])(\:[0-5]\d){1,2})[\s]?([AM|PM|am|pm]{2,2})?$


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