Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 670
  • Last Modified:

CDateTimeCtrl Problem

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;

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?
  • 3
  • 3
  • 2
  • +3
1 Solution
Meir RivkinFull stack Software EngineerCommented:
here's my code to diaply the time and it works fine:

     CTime 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?


Meir RivkinFull stack Software EngineerCommented:
i used your TRACE code also to check if its right and what can i say, it showed the current time.
are you calling GetTime before or after CDialog::OnOK - I suggest before
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


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().

ashaniAuthor Commented:
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...
> 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?
ashaniAuthor Commented:
There is VC 6.0 on all the machines..
There is also comctl32 here.
Which version or which file should I look for?
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.
> 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
Try switching to using COleDateTime.  Eg,:
//---------------- in OnInitDialog
COleDateTime timeNow;
m_datetimectrlTest.SetTime( timeNow );

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

COleDateTime timeInput;
m_datetimectrlTest.GetTime( timeInput );

TRACE1("Time is %d:%d.%d\n",

-- Dan
ashaniAuthor Commented:
Hi Dan, Thanks for your solution.Sorry I am very late.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now