Checking for valid dates - SOLVED

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ReverendDexter
Forum Contributor
Posts: 193
Joined: Tue May 29, 2007 1:26 pm
Location: Chico, CA

Checking for valid dates - SOLVED

Post by ReverendDexter »

Does anyone know of a way to check if a date is valid?

I'm currently using a regex string to check, but it lets a lot of invalid dates through, like 2007-01-39, or 2019-02-30. I'm currently only allowing for dates of the format yyyy-mm-dd, though I'm not opposed to opening that up.

Here's my current regex string:

Code: Select all

/2[0-9]{3}-(0[1-9]|[11,12])-[0-3][0-9]/
Is there a class or function I could be using?
Last edited by ReverendDexter on Tue Jul 24, 2007 6:38 pm, edited 1 time in total.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

checkdate() might be of interest
User avatar
ReverendDexter
Forum Contributor
Posts: 193
Joined: Tue May 29, 2007 1:26 pm
Location: Chico, CA

Post by ReverendDexter »

And very interesting it was.

Thank you, that did exactly what I needed.
Post Reply