?
Solved

DateTime Picker - CDateTimeCtrl

Posted on 2003-02-28
7
Medium Priority
?
396 Views
Last Modified: 2013-11-20
I am having trouble setting the value for the CDateTimeCtrl.  I use the following code below with the control format type defined as shortdate.  I Set the date to 2/28/2003 and the control displays 12/30/1899!  I would like to set the display format to "mm/dd/yyyy".
Any ideas?

Many thanks

void CTest::OnTest1()
{
   SYSTEMTIME sysTime;
   memset(&sysTime, 0, sizeof(sysTime));
   sysTime.wYear = 2003;
   sysTime.wMonth = 2;
   sysTime.wDay = 28;
   m_dt1.SetTime(&sysTime);
}
0
Comment
Question by:ramrocket
[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
7 Comments
 
LVL 23

Assisted Solution

by:Roshan Davis
Roshan Davis earned 150 total points
ID: 8046461
try these also

  // set with a CTime
  CTime timeTime(2003, 2, 28, 0, 0, 0);
  VERIFY(m_dt1.SetTime(&timeTime));

  // set with a COleDateTime object
  COleDateTime oletimeTime(2003, 2, 28, 0, 0, 0);
  VERIFY(m_dt1.SetTime(oletimeTime));


// setting format
CString formatStr= _T("'Today is: 'yy'/'MM'/'dd");
m_dt1.SetFormat(formatStr);



Good Luck
0
 
LVL 1

Expert Comment

by:Belfry
ID: 8046827
hi,ramrocket,your code is working on my computer, so what's the problem in your pc?btw, what's the default display on your control(is it like 12/30/1899?)?
0
 

Author Comment

by:ramrocket
ID: 8047623
roshmon, I did try using all 3 data types(CTime, COleDateTime,SYSTEMTIME).  The only one that doesnt cause an assertion is systemtime.

Belfry, any date that I set it to using systemtime, the display will always shows as 12/30/1899!  The default display on the control after initdialog is the current date.
0
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 

Author Comment

by:ramrocket
ID: 8048773
guys, I solve my problem by installing vs service pack 5.
thanks,
0
 

Accepted Solution

by:
streetsmart earned 150 total points
ID: 8227149

m_dt1.SetFormat("MM/dd/yyyy");
COleDateTime DtTime;
DtTime.SetDate( 2003, 2, 28 );
m_dt1.SetTime( cdt );
     
0
 

Author Comment

by:ramrocket
ID: 11628003
thank you guys.
0

Featured Post

Technology Partners: 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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

770 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