Re: CDate problem



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,

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
problem.
It just mystified me that it only reported those three dates wrong and not
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
do
a 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
the
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
"real"
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
string.

--
Mike
Microsoft MVP Visual Basic







.



Relevant Pages

  • Date Format
    ... I wish to include the date in the footer of my PowerPoint slides, ... the ISO standard yyyy-mm-dd, which is the only unambiguous format (and ...
    (microsoft.public.mac.office.powerpoint)
  • Re: Broken iWork 09 FACT
    ... XML content. ... So was the SXW format used by ... ODT, etc., were becoming an ISO standard, they created DOCX to confuse ...
    (comp.sys.mac.advocacy)
  • Re: Caculating Columns Between Certain Dates
    ... The format you are seeing is the standard SUMPRODUCT formula, ... you is a variation you will not see documented in the help files. ... UK based we suffer with Excel dates, so an ISO standard helps to make our ...
    (microsoft.public.excel.newusers)
  • Re: How to open Micrsofts so-called Open XML Format
    ... Microsoft Office Open XML Format Spreadsheet format. ... ISO standard document, claiming is is an "open" standard. ...
    (Ubuntu)
  • Re: Date format detection
    ... Specifies the locale for which the date string is to be formatted. ... date format for this locale. ... the system default-date format for the specified locale. ... be enclosed within single quotation marks in the date format picture. ...
    (borland.public.delphi.thirdpartytools.general)