CDate or CVDate

  • Thread starter Thread starter David
  • Start date Start date
D

David

Hi Group,

If MyValueDate < FirstDate Then Stop, problem is that MyDateValue is a
string and FirstDate is a Date.

I have tried CVDate(MyValueDate) and CDate(MyValueDate), but MyValueDate
remains a string.

Anyone help?
Thanks,
David
 
Use DateVaue to convert the string date to a real date, and then
compare that to your FirstDate date value. DateValue uses the Windows
regional settings to determine is the input string is a valid date and
what date it represents. E.g,

Dim FirstDate As Date
Dim MyDateValue As String
FirstDate = DateSerial(2009, 11, 5)
MyDateValue = "October 2, 2009"
If DateValue(MyDateValue) < FirstDate Then
Debug.Print "MyDateValue is earlier"
Else
Debug.Print "MyDateValue is later"
End If

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
How did you declare myValueDate--as a string, a date or a variant?

Dim myValueDate as Variant 'could be a date or string!
myvaluedate = "June 23, 1989"
myvaluedate = cdate(myvaluedate)
msgbox format(myvaluedate, "yyyy-mmmm-dd")
 
Back
Top