There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Date Time Parsing in VC++


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
del_ross's Avatar
Junior Member with 24 posts.
 
Join Date: Oct 2002
25-Jun-2005, 12:19 AM #1
Exclamation Date Time Parsing in VC++
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

Last edited by del_ross : 25-Jun-2005 12:22 AM. Reason: Addition
GCDude's Avatar
Senior Member with 400 posts.
 
Join Date: Apr 2005
Location: Brighton, UK
Experience: Possibly Competent
27-Jun-2005, 11:41 AM #2
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
GCDude's Avatar
Senior Member with 400 posts.
 
Join Date: Apr 2005
Location: Brighton, UK
Experience: Possibly Competent
27-Jun-2005, 11:45 AM #3
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.
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 02:44 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.