Date Time Parsing in VC++

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

del_ross

Thread Starter
Joined
Oct 24, 2002
Messages
24
Platform : VC++.NET/6.0
App: MDI app using a pair of Dialogs

Problem:
CDateTimeCtrl not displaying values correctly.

Scenario:
trying to retrieve date values directly from a listview control which has values fetched from a database.

WORKING code:
strDate=m_ctlList.GetItemText(nCurrRow,3);//placing value from listview into //a CString
//converting the values to numbers
nDay=atoi(strDate.Left(2));
nMon=atoi(strDate.Mid(3,2));
nYear=atoi(strDate.Right(4));

//setting the value in COleDateTime variable
codtDDate.SetDate(nYear,nMon,nDay);
====================================================

however i decided that took too many function calls and
started to use the ParseDateTime() function like so......
(1033 = English Locale ID)

codtDDate.ParseDateTime(strDate,VAR_DATEVALUEONLY,1033);

====================================================

the values im getting a screwy output with is "04-06-2005" (thats how it appears in the Listview : DD-MM-YYYY)

parsedatetime flips it over to read the 6th of April,2005(06/04/2005) instead of the 4th of June.

ADDITION: the Dialog in which im displaying the retrieved values in a CDateTimeCtrl .... contains following in the OnInitDialog()

//m_dtpBorrowed = Control variable for CDateTimeCtrl
m_dtpBorrowed.SetFormat("dd/MM/yyyy");
....

any suggestions welcome :)

- it'd be helpful if someone could tell me what are the advantages of ParseDateTime() ?? over the manual way i m using
 
Joined
Apr 1, 2005
Messages
394
because u are specifying the US locale ID and the americans put the month first by default. If you want it the 'right' way around ;) use 2057 as the locale id to specify UK settings
 
Joined
Apr 1, 2005
Messages
394
oh and as for the other questions, using ParseDateTime with a locale id probably overrides the SetFormat settings. Advantages of ParseDateTime is that its one method to specify date rather than 3 assigns u were originally doing plus u get the benefit of using LANG_USER_DEFAULT to use regional settings on the persons pc running your program.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top