Setting the date on a dategadget()

Just starting out? Need help? Post your questions and find answers here.
User avatar
tikidays
User
User
Posts: 46
Joined: Tue Oct 24, 2023 6:47 am
Location: New Zealand
Contact:

Setting the date on a dategadget()

Post 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.
User avatar
tikidays
User
User
Posts: 46
Joined: Tue Oct 24, 2023 6:47 am
Location: New Zealand
Contact:

Re: Setting the date on a dategadget()

Post 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?
User avatar
ChrisR
Addict
Addict
Posts: 1466
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Setting the date on a dategadget()

Post by ChrisR »

You can look at the help for FormatDate() and ParseDate()
swan
Enthusiast
Enthusiast
Posts: 226
Joined: Sat Jul 03, 2004 9:04 am
Location: Sydney Australia
Contact:

Re: Setting the date on a dategadget()

Post 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))
normeus
Enthusiast
Enthusiast
Posts: 472
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: Setting the date on a dategadget()

Post 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.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
BarryG
Addict
Addict
Posts: 4178
Joined: Thu Apr 18, 2019 8:17 am

Re: Setting the date on a dategadget()

Post 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?
User avatar
mk-soft
Always Here
Always Here
Posts: 6252
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Setting the date on a dategadget()

Post by mk-soft »

PB has not yet been converted to internal _time64.
But I assume that it will be done by 2038.

Module DateTime
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
tikidays
User
User
Posts: 46
Joined: Tue Oct 24, 2023 6:47 am
Location: New Zealand
Contact:

Re: Setting the date on a dategadget()

Post 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
Post Reply