ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help with regular expression (https://www.excelbanter.com/excel-programming/388552-help-regular-expression.html)

PO

Help with regular expression
 
Hi,

Can anybody help me with a regular expressions pattern for a date?

YYYY-MM-DD

i.e. 2007-05-02
The year may range between 2000 and 2010.

TIA
po



Dave Peterson

Help with regular expression
 
If that value is really a date, you could just use

dim myDate as date
mydate = dateserial(2007,5,2)

if year(mydate) < 2000 _
or year(mydate) 2010 then
'error
else
'ok
end if



PO wrote:

Hi,

Can anybody help me with a regular expressions pattern for a date?

YYYY-MM-DD

i.e. 2007-05-02
The year may range between 2000 and 2010.

TIA
po


--

Dave Peterson

Dave Peterson

Help with regular expression
 
And if it's not really a date (just a plain old string), why not just extract
the first 4 characters with Left?

PO wrote:

Hi,

Can anybody help me with a regular expressions pattern for a date?

YYYY-MM-DD

i.e. 2007-05-02
The year may range between 2000 and 2010.

TIA
po


--

Dave Peterson

Dana DeLouis

Help with regular expression
 
Not a regular expression, but would either of these work?

Function IsValidDate(sDte) As Boolean
Dim dte As Date
If IsDate(sDte) Then dte = CDate(sDte)
IsValidDate = Year(dte) = 2000 And Year(dte) <= 2010
End Function

Function IsValidDate2(sDte) As Boolean
Const Ptn1 As String = "200#-##-##"
Const Ptn2 As String = "2010-##-##"
IsValidDate2 = sDte Like Ptn1 Or sDte Like Ptn2
End Function

--
HTH :)
Dana DeLouis
Windows XP & Office 2007


"PO" <h wrote in message ...
Hi,

Can anybody help me with a regular expressions pattern for a date?

YYYY-MM-DD

i.e. 2007-05-02
The year may range between 2000 and 2010.

TIA
po





All times are GMT +1. The time now is 09:47 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com