wxDatePickerCtrl and arithmetic operations Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
YuMERA
Knows some wx things
Knows some wx things
Posts: 44
Joined: Fri Jul 05, 2019 8:47 pm

wxDatePickerCtrl and arithmetic operations

Post by YuMERA »

It's possible?
I have one wxDatePickerCtrl and i know GetValue() returning wxDateTime.
I need like something :
SetValue() = GetValue() - 1day;
SetValue() = GetValue() - 1month;
SetValue() = GetValue() - 1year;

Maybe is simple for this or must parse date and create value...

If possible this pls example how.
Thx
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxDatePickerCtrl and arithmetic operations

Post by PB »

Please check the documentation of both wxDatePickerCtrl and wxDateTime (in particular the Date Arithmetics section), it will become obvious what you can and cannot do.

But even without checking the API, it is pretty clear you cannot do something like this

Code: Select all

SetValue() = GetValue() ...
as SetValue() method of wxWidgets controls always takes a value and returns void.

And you can do things like this

Code: Select all

wxDateTime dt = wxDateTime::Now();
dt.Subtract(wxDateSpan(0,1)); // subtract a month
YuMERA
Knows some wx things
Knows some wx things
Posts: 44
Joined: Fri Jul 05, 2019 8:47 pm

Re: wxDatePickerCtrl and arithmetic operations

Post by YuMERA »

Thanks for the useful info.
This code is what I need for -1 month

Code: Select all

	wxDateTime dt = wxDateTime::Now();
        dt.Subtract(wxDateSpan(0,1));
        dpOd->SetValue(dt);
        wxString do_date = dpOd->GetValue()).Format("%Y-%m-%d");
Post Reply