Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Old May 2nd 07, 10:50 AM posted to microsoft.public.excel.programming
PO PO is offline
external usenet poster
 
First recorded activity by ExcelBanter: Aug 2006
Posts: 66
Default 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



  #2   Report Post  
Old May 2nd 07, 01:13 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Jul 2006
Posts: 35,218
Default 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
  #3   Report Post  
Old May 2nd 07, 01:14 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Jul 2006
Posts: 35,218
Default 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
  #4   Report Post  
Old May 2nd 07, 01:39 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Jul 2006
Posts: 947
Default 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





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can someone help me with this regular expression? [email protected] Excel Discussion (Misc queries) 3 March 10th 09 07:36 PM
Excel formula needed... regular expression? danesh Excel Discussion (Misc queries) 3 August 10th 07 12:31 PM
Regular Expression sl Excel Discussion (Misc queries) 2 January 23rd 07 11:57 PM
Regular Expression for cell address M. Authement Excel Programming 11 January 4th 07 08:57 PM
Regular expression searching problem LarryLev Excel Programming 0 September 15th 05 07:44 PM


All times are GMT +1. The time now is 11:58 AM.

Powered by vBulletin® Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright 2004-2019 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"

 

Copyright © 2017