Click here to Skip to main content
15,884,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am using the date-time control picker.

Is there an easier way to subtract or add any number of days from the selected date or will I have to do a manual calculation and set the date?


Any help will be greatly appreciated.

Thanks in advance.
Posted
Comments
chaau 5-Feb-14 23:14pm    
Is it pure C++, or you can use MFC?
FISH786 5-Feb-14 23:30pm    
I can use MFC.

1 solution

If you use MFC then the simplest way to add days is to use COleDateTime() class for the dates from the DateTime picker together with COleDateTimeSpan class to add/subtract the days:
C++
CDateTimeCtrl *pDt = (CDateTimeCtrl*)GetDlgItem(IDC_DATEPICKER1);
COleDateTime dt1;
pDt->GetTime(dt1);
COleDateTimeSpan Day(1, 0, 0, 0);
COleDateTimeSpan Days2(2, 0, 0, 0);
COleDateTime tomorrow = dt1 + Day;
COleDateTime beforeYesterday = dt1 - Days2;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900