wxDateTime and date validation

34 views
Skip to first unread message

Tim Burgess

unread,
Apr 30, 2025, 6:02:17 AM4/30/25
to wx-u...@googlegroups.com

Hi,

 

I have some code that stores a date generated from a wxDatePicker in ISO format:

 

datePicker->GetValue().FormatISODate()

 

Example result:

 

2020-01-01

 

However, I’m failing to retrieve this stored value in a form that I can use to set the value of the wxDatePicker. Here’s my code:

 

wxString temp = “2020-01-01

”;

wxDateTime myDate.ParseISODate(temp);

 

In this example, myDate takes the value wxInvalidDateTime.

 

My project requires that I store the date in ISO format and I assume I’m missing something simple.

 

Any and all suggestions would be most welcome.

 

Best wishes.

 

Tim

 

 

Rossano Paris

unread,
Apr 30, 2025, 6:43:39 AM4/30/25
to wx-users
Did you try with the following code?

wxString temp = “2020-01-01”;
wxDateTime myDate;
myDate.ParseISODate(temp);


Tim Burgess

unread,
Apr 30, 2025, 7:22:09 AM4/30/25
to wx-u...@googlegroups.com
Yes,with the same result
best wishes.

Tim Burgess


On 30 Apr 2025, at 11:43, Rossano Paris <parisr...@gmail.com> wrote:

Did you try with the following code?
--
Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
---
You received this message because you are subscribed to the Google Groups "wx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wx-users+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/wx-users/0240494c-e602-41f4-a647-c8bec45e57b8n%40googlegroups.com.

Paris Rossano

unread,
Apr 30, 2025, 8:17:59 AM4/30/25
to wx-u...@googlegroups.com, Tim Burgess
It works on my side ... please see the attached image.
I suspect your problem is due to other than wx itself

Is the code executed in an application (EXE) or in a library (DLL)?
parse-date.png

PB

unread,
Apr 30, 2025, 8:41:45 AM4/30/25
to wx-users
Hi,

I can confirm this works as expected with wxWidgets 3.2.8 and GIT Master on Windows, tested with
 const wxString isoDateSrcStr("2020-01-01");
 wxDateTime dt;

 if ( dt.ParseDate(isoDateSrcStr) )
 {
     wxString isoDateDstStr = dt.FormatISODate();

     if ( isoDateDstStr == isoDateSrcStr )
         wxLogMessage("ISO date roundtrip successful: %s", isoDateDstStr);
     else
         wxLogError("ISO date roundtrip unsuccessful: %s vs %s", isoDateSrcStr, isoDateDstStr);
 }
 else
     wxLogError("Could not parse ISO date %s", isoDateSrcStr);

I have also checked whether it matters if the datetime was valid (had value) before parsing: It does not.

Best,
PB 

PB

unread,
Apr 30, 2025, 8:53:57 AM4/30/25
to wx-users
Ooops, I had a typo in the code in my previous post, using ParseDate() instead of ParseISODate()

The conclusion still stands though, full corrected code:
        const wxString isoDateSrcStr("2020-01-01");
       
wxDateTime dt;

        if ( dt.ParseISODate(isoDateSrcStr) )
Reply all
Reply to author
Forward
0 new messages