Re: CDate problem
- From: "Tony Proctor" <tony_proctor@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 2 Jul 2007 13:48:47 +0100
You can Norm. There's an ISO standard date format that was designed for
situations like this. If you save your dates in ISO 8601 format then you'll
be able to load them back correctly no matter how your users are expecting
to see their dates on the screen.
For instance, when you come to save your dates to your text file, explicitly
format them as follows:
Format$ (dDateVal, "yyyy-mm-dd")
and when you're reading them back from the file:
dDateVal = CDate (sISODate)
where sISODate might contain something like "2007-07-02"
(needless to say, dDateVal is a proper Date variable here, declared with 'As
Date' as per Mike's response)
Tony Proctor
"Norm" <NormF4@xxxxxxxxxxxxxxxxx> wrote in message
news:ebV15ryuHHA.4412@xxxxxxxxxxxxxxxxxxxxxxx
Hi Mike,problem.
I am not sure I can do that in this instance. I am displaying the date,
along with a golf score, course rating and course slope in a tabbed list
box.
All of this information is being stored in a text file as backup.
But your suggestion sure makes a lot of sense to avoid this type of
It just mystified me that it only reported those three dates wrong and notdo
all the others. <g>
Thanks for the information.
--
Norm
Don't blame me, my programming is
self-taught and my teacher was not
very experienced. :-)
normfowler_don't use_@xxxxxxxxxxx
"MikeD" <nobody@xxxxxxxxxxx> wrote in message
news:OTiWvcxuHHA.536@xxxxxxxxxxxxxxxxxxxxxxx
"Norm" <NormF4@xxxxxxxxxxxxxxxxx> wrote in message
news:%23Ml0VdruHHA.5028@xxxxxxxxxxxxxxxxxxxxxxx
Hi,
I am using the following code:
Dim order as Long
Dim strName as string
order = CLng(CDate(strName))
When strName = "04/30/07" CDate changes to 2007/04/30 and order = 39202
But the string "05/02/07" CDate changes to 2005/02/07 and order = 38390
It has this same problem with "05/04/07" and "05/11/07" but then shows
"05/14/07" correctly as 2007/05/14.
Does anyone know why the CDate function is doing this? I have tried to
thea Format$(strName,"mm/dd/yyyy", but still get the same results on these
three dates.
FYI since you already got an answer and solved it....
The underlying problem is that your using strings for your dates. Use
"real"Date data type. If you need to obtain a date from a user, use something
like the MonthView or DateTimePicker controls so that you've got a
string.date rather than a string representation of the date. Do NOT use a
TextBox or MaskedEditBox or any other control where the data is a
--
Mike
Microsoft MVP Visual Basic
.
- Follow-Ups:
- Re: CDate problem
- From: Saga
- Re: CDate problem
- Prev by Date: Re: Dim, var, & why?
- Next by Date: Re: Trace debugging in run-time (re-direct Debug.Print to a file?)
- Previous by thread: running sql query in vb6
- Next by thread: Re: CDate problem
- Index(es):
Relevant Pages
|