Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default CDate and IsDate

Hi
The following test fails using CDate, can anyone explain why and how I can
produce the correct answer 'is not valid'? As it is, CDate evaluates the
invalid year 0000 to 2000 and results in an 'out of range' result incorrectly.

Input to 3 textboxes gives:
txtDay.Text = 12
txtMonth.Text = 05
txtYear.Text = 0000

tmpdate = CDate(txtDay.Text & "/" & txtMonth.Text & "/" & txtYear.Text)
If IsDate(tmpdate) = False Then
MsgBox "Please re-enter, " & txtSDay.Text & "/" & txtSMonth.Text & "/" &
txtSYear.Text & " is not valid. ")
Exit Sub
ElseIf tmpdate < DateAdd("yyyy", -1, Now()) Or tmpdate Now() Then
MsgBox "Please re-enter, " & txtDay.Text & "/" & txtMonth.Text & "/" &
txtYear.Text & " is not within range. ")
End If

T.I.A

Geoff
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default CDate and IsDate

Try

tmpdate = dateValue(txtDay.Text & "/" & txtMonth.Text & "/" & txtYear.Text)


--
HTH

Bob Phillips

"Geoff" wrote in message
...
Hi
The following test fails using CDate, can anyone explain why and how I can
produce the correct answer 'is not valid'? As it is, CDate evaluates the
invalid year 0000 to 2000 and results in an 'out of range' result

incorrectly.

Input to 3 textboxes gives:
txtDay.Text = 12
txtMonth.Text = 05
txtYear.Text = 0000

tmpdate = CDate(txtDay.Text & "/" & txtMonth.Text & "/" & txtYear.Text)
If IsDate(tmpdate) = False Then
MsgBox "Please re-enter, " & txtSDay.Text & "/" & txtSMonth.Text & "/"

&
txtSYear.Text & " is not valid. ")
Exit Sub
ElseIf tmpdate < DateAdd("yyyy", -1, Now()) Or tmpdate Now() Then
MsgBox "Please re-enter, " & txtDay.Text & "/" & txtMonth.Text & "/" &
txtYear.Text & " is not within range. ")
End If

T.I.A

Geoff



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default CDate and IsDate

Hi Bob
No, 0000 still evaluates to 2000.
Researching further, permitted dates go back as far as Jan 1 100AD so 0000
should fail when using IsDate.

Geoff

"Bob Phillips" wrote:

Try

tmpdate = dateValue(txtDay.Text & "/" & txtMonth.Text & "/" & txtYear.Text)


--
HTH

Bob Phillips

"Geoff" wrote in message
...
Hi
The following test fails using CDate, can anyone explain why and how I can
produce the correct answer 'is not valid'? As it is, CDate evaluates the
invalid year 0000 to 2000 and results in an 'out of range' result

incorrectly.

Input to 3 textboxes gives:
txtDay.Text = 12
txtMonth.Text = 05
txtYear.Text = 0000

tmpdate = CDate(txtDay.Text & "/" & txtMonth.Text & "/" & txtYear.Text)
If IsDate(tmpdate) = False Then
MsgBox "Please re-enter, " & txtSDay.Text & "/" & txtSMonth.Text & "/"

&
txtSYear.Text & " is not valid. ")
Exit Sub
ElseIf tmpdate < DateAdd("yyyy", -1, Now()) Or tmpdate Now() Then
MsgBox "Please re-enter, " & txtDay.Text & "/" & txtMonth.Text & "/" &
txtYear.Text & " is not within range. ")
End If

T.I.A

Geoff




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default CDate and IsDate

Further testing reveals:
From 01 Jan 0001 to 31 Dec 0029 the year is returned as 20xx
From 01 Jan 0030 to 31 Dec 0099 the year is returned as 19xx
From 01 Jan 0100 the year is returned correctly.

Both IsDate and CDate operate on the same basis.

Clearly I must test the year txtbox component separately for zero.

Geoff

"Geoff" wrote:

Hi Bob
No, 0000 still evaluates to 2000.
Researching further, permitted dates go back as far as Jan 1 100AD so 0000
should fail when using IsDate.

Geoff

"Bob Phillips" wrote:

Try

tmpdate = dateValue(txtDay.Text & "/" & txtMonth.Text & "/" & txtYear.Text)


--
HTH

Bob Phillips

"Geoff" wrote in message
...
Hi
The following test fails using CDate, can anyone explain why and how I can
produce the correct answer 'is not valid'? As it is, CDate evaluates the
invalid year 0000 to 2000 and results in an 'out of range' result

incorrectly.

Input to 3 textboxes gives:
txtDay.Text = 12
txtMonth.Text = 05
txtYear.Text = 0000

tmpdate = CDate(txtDay.Text & "/" & txtMonth.Text & "/" & txtYear.Text)
If IsDate(tmpdate) = False Then
MsgBox "Please re-enter, " & txtSDay.Text & "/" & txtSMonth.Text & "/"

&
txtSYear.Text & " is not valid. ")
Exit Sub
ElseIf tmpdate < DateAdd("yyyy", -1, Now()) Or tmpdate Now() Then
MsgBox "Please re-enter, " & txtDay.Text & "/" & txtMonth.Text & "/" &
txtYear.Text & " is not within range. ")
End If

T.I.A

Geoff




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
IsDate? Arne Hegefors Excel Worksheet Functions 3 January 30th 07 01:44 PM
CDATE issues Marcus Excel Programming 1 November 12th 04 10:02 AM
CDate cannot coerce value of IsDate(true)? tkstock[_4_] Excel Programming 1 November 1st 04 04:34 PM
IsDate Function Don Lloyd Excel Programming 14 August 23rd 04 05:57 AM
What is the differance between cdate and ... Bruccce Excel Programming 3 August 7th 03 09:00 PM


All times are GMT +1. The time now is 09:32 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"