Page 1 of 1

Setting the date on a dategadget()

Posted: Tue Nov 14, 2023 12:04 am
by tikidays
Hi,

How do I set the date on a DATEGADGET() after its being created? The help states the below:

SetGadgetState(): Set the currently displayed date.

But offers no example and I get an error if I try to sublist a string "13/10/22" for example, stating it needs a number.

Code: Select all

        r.s =  ReadString(0) 
        SetGadgetState(Dated, r.s)
Results in: Error 81 Number expected

I have obviously missed something here. If I use SetGadgetText() the popup calendar no longer works, I think this is used for date format mask only.

Re: Setting the date on a dategadget()

Posted: Tue Nov 14, 2023 12:36 am
by tikidays
Discovered by using getgadgetstate() this is a date number derived from the seconds since 1970. So have solved the problem. It would be helpful in the help preferences this date number requirement for the DateGadget()

Is there an easy way to convert a date in a string to and from this number?

Re: Setting the date on a dategadget()

Posted: Tue Nov 14, 2023 12:44 am
by ChrisR
You can look at the help for FormatDate() and ParseDate()

Re: Setting the date on a dategadget()

Posted: Tue Nov 14, 2023 12:46 am
by swan
Try this:

Code: Select all

DateFromDatabase.s = "2023-11-14 17:00:00" ; datetime source
Date.s = StringField(DateFromDatabase, 1, " ") ; filter date only
SetGadgetState(#Date, ParseDate("%dd/%mm/%yyyy", Date))

Re: Setting the date on a dategadget()

Posted: Tue Nov 14, 2023 12:54 am
by normeus

Code: Select all

Note: supported date/time values are 1970-01-01, 00:00:00 for the minimum and 2038-01-19, 03:14:07 for the maximum.
It has always bothered me. There are multiple libraries in the forums that use 64 bits, look for those.

https://en.wikipedia.org/wiki/Year_2038_problem

Norm.

Re: Setting the date on a dategadget()

Posted: Tue Nov 14, 2023 2:40 am
by BarryG
tikidays wrote: Tue Nov 14, 2023 12:36 amIt would be helpful in the help preferences this date number requirement for the DateGadget()
All "SetGadgetText" commands take a string, and all "SetGadgetState" commands take a number.

Fred: Maybe the manual needs to explicitly mention this for the benefit of newbies to PureBasic?

Re: Setting the date on a dategadget()

Posted: Tue Nov 14, 2023 9:05 am
by mk-soft
PB has not yet been converted to internal _time64.
But I assume that it will be done by 2038.

Module DateTime

Re: Setting the date on a dategadget()

Posted: Tue Nov 14, 2023 7:04 pm
by tikidays
swan wrote: Tue Nov 14, 2023 12:46 am Try this:

Code: Select all

DateFromDatabase.s = "2023-11-14 17:00:00" ; datetime source
Date.s = StringField(DateFromDatabase, 1, " ") ; filter date only
SetGadgetState(#Date, ParseDate("%dd/%mm/%yyyy", Date))
Thanks for this :D