Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default CDate or CVDate

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default CDate or CVDate

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)


On Wed, 5 Aug 2009 17:14:09 -0700, David
wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default CDate or CVDate

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")



David wrote:

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


--

Dave Peterson
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
cdate problem JohnP Excel Programming 3 April 1st 08 06:17 PM
CDate Problem sil0000 Excel Programming 7 July 22nd 05 08:24 AM
CDate and IsDate Geoff Excel Programming 3 June 4th 05 02:20 PM
CDATE issues Marcus Excel Programming 1 November 12th 04 10:02 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 05:53 AM.

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

About Us

"It's about Microsoft Excel"