Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 412
  • Last Modified:

DateTime Picker - CDateTimeCtrl

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
ramrocket
Asked:
ramrocket
2 Solutions
 
Roshan DavisCommented:
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
 
BelfryCommented:
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
 
ramrocketAuthor Commented:
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
Independent Software Vendors: 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!

 
ramrocketAuthor Commented:
guys, I solve my problem by installing vs service pack 5.
thanks,
0
 
streetsmartCommented:

m_dt1.SetFormat("MM/dd/yyyy");
COleDateTime DtTime;
DtTime.SetDate( 2003, 2, 28 );
m_dt1.SetTime( cdt );
     
0
 
ramrocketAuthor Commented:
thank you guys.
0

Featured Post

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now