Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 128
Default Testing for <Incorrect Dates

I have somedates in this text/label format (yyyy-mm-dd) i.e. not numbers,

2007-02-01

2007-01-33

2007-02-01



I want to test for valid dates. The basic approach I was using was this:



Sub foo()

Dim sDateStr As String



sDateStr = "2007-01-33"

Debug.Print DateSerial(Left(sDateStr, 4), Mid(sDateStr, 6, 2),
Right(sDateStr, 2))

Debug.Print IsDate(DateSerial(Left(sDateStr, 4), Mid(sDateStr, 6, 2),
Right(sDateStr, 2)))



End Sub



But pseudo-dates such as

33rd January 2007 (see second entry)

get interpreted as 2nd February 2007 and *pass* the test.



What is the best way of testing for such pseudo-dates, please?



Thanks in advance



Tim


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default Testing for <Incorrect Dates

I have somedates in this text/label format (yyyy-mm-dd) i.e. not numbers,

2007-02-01

2007-01-33

2007-02-01

I want to test for valid dates. The basic approach I was using was this:



Sub foo()

Dim sDateStr As String

sDateStr = "2007-01-33"

Debug.Print DateSerial(Left(sDateStr, 4), Mid(sDateStr, 6, 2),
Right(sDateStr, 2))

Debug.Print IsDate(DateSerial(Left(sDateStr, 4), Mid(sDateStr, 6, 2),
Right(sDateStr, 2)))

End Sub

But pseudo-dates such as

33rd January 2007 (see second entry)

get interpreted as 2nd February 2007 and *pass* the test.

What is the best way of testing for such pseudo-dates, please?


If IsDate(sDateStr) Then
' Date is OK
Else
' Date is bogus
End If

Rick
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 128
Default Testing for <Incorrect Dates

Hi Rick

thanks - very straightforward. I just wish I had been able to puzzle it out
myself!

bw

Tim

"Rick Rothstein (MVP - VB)" wrote in
message ...
I have somedates in this text/label format (yyyy-mm-dd) i.e. not numbers,

2007-02-01

2007-01-33

2007-02-01

I want to test for valid dates. The basic approach I was using was this:



Sub foo()

Dim sDateStr As String

sDateStr = "2007-01-33"

Debug.Print DateSerial(Left(sDateStr, 4), Mid(sDateStr, 6, 2),
Right(sDateStr, 2))

Debug.Print IsDate(DateSerial(Left(sDateStr, 4), Mid(sDateStr, 6, 2),
Right(sDateStr, 2)))

End Sub

But pseudo-dates such as

33rd January 2007 (see second entry)

get interpreted as 2nd February 2007 and *pass* the test.

What is the best way of testing for such pseudo-dates, please?


If IsDate(sDateStr) Then
' Date is OK
Else
' Date is bogus
End If

Rick



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Testing for <Incorrect Dates

? isdate("3rd January 2007")
False

is that what you meant?

I guess I misunderstood your intentions.

--
Regards,
Tom Ogilvy


"Tim Childs" wrote:

Hi Rick

thanks - very straightforward. I just wish I had been able to puzzle it out
myself!

bw

Tim

"Rick Rothstein (MVP - VB)" wrote in
message ...
I have somedates in this text/label format (yyyy-mm-dd) i.e. not numbers,

2007-02-01

2007-01-33

2007-02-01

I want to test for valid dates. The basic approach I was using was this:



Sub foo()

Dim sDateStr As String

sDateStr = "2007-01-33"

Debug.Print DateSerial(Left(sDateStr, 4), Mid(sDateStr, 6, 2),
Right(sDateStr, 2))

Debug.Print IsDate(DateSerial(Left(sDateStr, 4), Mid(sDateStr, 6, 2),
Right(sDateStr, 2)))

End Sub

But pseudo-dates such as

33rd January 2007 (see second entry)

get interpreted as 2nd February 2007 and *pass* the test.

What is the best way of testing for such pseudo-dates, please?


If IsDate(sDateStr) Then
' Date is OK
Else
' Date is bogus
End If

Rick




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
Dates Incorrect in Chart Jim Charts and Charting in Excel 5 October 11th 08 03:15 PM
Testing Richard Wrigley Excel Discussion (Misc queries) 0 November 1st 06 09:45 PM
Reformatting incorrect dates KDJ Excel Programming 2 August 21st 05 02:59 PM
testing Mitchina New Users to Excel 2 June 21st 05 04:35 PM
testing Juco Excel Worksheet Functions 2 January 31st 05 01:13 AM


All times are GMT +1. The time now is 12:34 PM.

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

About Us

"It's about Microsoft Excel"