Solved

CDateTimeCtrl Problem

Posted on 2001-07-19
11
636 Views
Last Modified: 2013-11-20
I have a Dialog based application. I added a CDateTimeCtrl to the Dialog template. I added a member variable to the Dialog class of Type CDateTimeCtrl as m_datetimectrlTest. (Using Class Wizard)

When I try to retrieve the time as(say in OnOk() )

CTime mytime;
m_datetimectrlTest.GetTime(time);

TRACE1("Time is %s\n",time.Format("%Hhr%Mmin%Ssec") );

Time is always showing 23 hr 59 min 13 sec ??!!

Can anyone give some hints what the problem could be?
0
Comment
Question by:ashani
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +3
11 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 6297645
here's my code to diaply the time and it works fine:

     CTime mytime;
     m_datetimectrlTest.GetTime(mytime);
     
     int Day = mytime.GetDay();
     int Month = mytime.GetMonth();
     int Year = mytime.GetYear();
     int Minute = mytime.GetMinute();
     int Hour = mytime.GetHour();
     int Second = mytime.GetSecond();

     CString strTime;
     strTime.Format("%d.%d.%d, %d::%d::%d", Month,Day,Year,Hour,Minute,Second);

     TRACE1("Time is %s\n", strTime);

any questions?

     

0
 
LVL 42

Expert Comment

by:sedgwick
ID: 6297661
i used your TRACE code also to check if its right and what can i say, it showed the current time.
0
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 6297769
are you calling GetTime before or after CDialog::OnOK - I suggest before
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 31

Expert Comment

by:Zoppo
ID: 6297793
Hi,

I also made a little test. The GetTime always returned a CTime with the current time and the
selected date. When I add time-values using CDateTimeCtrl::SetFormat() I can change the
time in the edit-control of the date-time-control and this modified time is returned by GetTime().

ZOPPO
0
 
LVL 1

Author Comment

by:ashani
ID: 6300929
I tested this code on a few other machines..I worked fine on every machine except two!!
Could this be a problem with some library version or installation or something...
0
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 6301259
> Could this be a problem with some library version or installation or something...

it's possible the control is hosted in comctl32 what versions do you have on the machines?
0
 
LVL 1

Author Comment

by:ashani
ID: 6302274
There is VC 6.0 on all the machines..
There is also comctl32 here.
Which version or which file should I look for?
0
 

Expert Comment

by:ahphone
ID: 6304664
I once found the value of the time under debug mode is different from that under release mode.
Under the debug mode ,the date and time is current date and time.But under the release mode, the date and time is 1980/1/1 00:00:00.
0
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 6305121
> Which version or which file should I look for

well what version(s) is/are working - and then make sure it is availabe on the other machines
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 100 total points
ID: 6306498
Try switching to using COleDateTime.  Eg,:
//---------------- in OnInitDialog
COleDateTime timeNow;
timeNow.GetCurrentTime();
m_datetimectrlTest.SetTime( timeNow );

//---------------- in OnOK or whenever...

COleDateTime timeInput;
m_datetimectrlTest.GetTime( timeInput );

TRACE1("Time is %d:%d.%d\n",
   timeInput.GetHour(),
   timeInput.GetMinute(),
   timeInput.GetSecond()
);

-- Dan
0
 
LVL 1

Author Comment

by:ashani
ID: 6336734
Hi Dan, Thanks for your solution.Sorry I am very late.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Adapt this command to show who installed 29 114
Host to IP 7 84
CRON statement to run every 3 minutes except on Monday morning 12am to 2am 7 123
format the code in java 6 117
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question