Problem with date

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

SparkOut
Posts: 2984
Joined: Sun Sep 23, 2007 4:58 pm

Re: Problem with date

Post by SparkOut »

See the dictionary entry for "useSystemDate"
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10415
Joined: Fri Feb 19, 2010 10:17 am

Re: Problem with date

Post by richmond62 »

That appears to be non-functional:
-
Screenshot 2025-08-20 at 18.23.17.jpg
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Problem with date

Post by Klaus »

USESYSTEMDATE is a LOCAL property!
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10415
Joined: Fri Feb 19, 2010 10:17 am

Re: Problem with date

Post by richmond62 »

Right . . .

In a button setting it to false:
-
Screenshot 2025-08-20 at 18.27.56.png
-
It does noting, as advertised.

In a button setting it to true
-
Screenshot 2025-08-20 at 18.28.30.png
-
It DOES change the format, and also mucks around with the itemDelimiter. :cry:

What is hilarious about this is that when I was at school (in England) our History teacher would write the date 8/20/2025 (well, he wouldn't as that was 1975). and our Maths teacher would write it 8.20.2025 . . .
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10415
Joined: Fri Feb 19, 2010 10:17 am

Re: Problem with date

Post by richmond62 »

And, in a global world better tools are needed:
-
tDate.png
-
Robot says:
-
marvin-the-paranoid-android.jpg
-
scholars estimate that roughly 40-50 distinct calendar systems are still actively used today in some capacity
FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10103
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Problem with date

Post by FourthWorld »

richmond62 wrote: Wed Aug 20, 2025 4:43 pm And, in a global world better tools are needed...
There must be something in those images I'm not noticing.

xTalks use a default date format internally for computational consistency, and through useSystemDate LC accesses the user's preference expressed in OS settings for display.

Under what circumstance is the user's preference wrong?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
CAsba
Posts: 452
Joined: Fri Sep 30, 2022 12:11 pm

Re: Problem with date

Post by CAsba »

Hi Klaus,
Here is the code..

Code: Select all

  if fld "dateready" is 3 then
      set the itemdelimiter to "/"   
      put word 1 of fld "startday" into sday
      put word 1 of  fld "startyr" into syr
      put word 1 of  fld "startmth" into smth
      put sday & "/" & smth & "/" & syr into tdate
      put sday & "/" & smth & "/" & syr into tdate2
      convert tdate2 to seconds 
      #answer tdate2
      #convert tdate2 to system date
      #convert tdate2 to seconds 
      put tdate2 into fld "date3"
      show  fld "announce81"
      put "The start date of the current business trading year is" & CR &   tdate into fld "announce81"
      convert the date to seconds
      put it into date2
      put it into fld "date2"
      put fld "date2" - fld "date3" into fld "temp1"
      put 60*60*24*365 into date4
      put 60*60*24*365 into fld "date4"
      if fld "temp1" > fld "date4" then
         put "nogo" into fld "temp2"
      end if
      if fld "temp2" is "nogo" then
         answer "That date is more than a year ago, so cannot refer to the current year. Try again"
         hide fld "announce81"
         put empty into fld "temp2"
         put empty into fld "temp1"
         put empty into fld "date2"
         put empty into fld "date3"
         put empty into fld "date4"
         exit mouseup
      end if
      
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10415
Joined: Fri Feb 19, 2010 10:17 am

Re: Problem with date

Post by richmond62 »

Is it just me, or?

Code: Select all

fld "dateready" is 3 then
or, might that not be:

Code: Select all

fld "dateready" contains 3 then
CAsba
Posts: 452
Joined: Fri Sep 30, 2022 12:11 pm

Re: Problem with date

Post by CAsba »

Just you I'm guessing,

Code: Select all

fld "dateready" is 3
as in

Code: Select all

fld "dateready" = 3
CAsba
Posts: 452
Joined: Fri Sep 30, 2022 12:11 pm

Re: Problem with date

Post by CAsba »

HI all,
I think I finally got it figured with this code

Code: Select all

 if fld "dateready" is 3 then
      set the itemdelimiter to "/"   
      put word 1 of fld "startday" into sday
      put word 1 of  fld "startyr" into syr
      put word 1 of  fld "startmth" into smth
      put smth & "/" & sday & "/" & syr into tdate2
      put sday & "/" & smth & "/" & syr into tdate
      convert tdate from system date to long english date
      convert tdate2 to seconds 
      put tdate2 into fld "date3"
      show  fld "announce81"
      put "The start date of the current business trading year is" & CR &   tdate into fld "announce81"
      convert the date to seconds
      put it into date2
      put it into fld "date2"
      put fld "date2" - fld "date3" into fld "temp1"
      put 60*60*24*365 into date4
      put 60*60*24*365 into fld "date4"
      if fld "temp1" > fld "date4" then
         put "nogo" into fld "temp2"
      end if
      if fld "temp2" is "nogo" then
         answer "That date is more than a year ago, so cannot refer to the current year. Try again."titled field "fieldboxtitle" of cd "template1"
         hide fld "announce81"
         put empty into fld "temp2"
         put empty into fld "temp1"
         put empty into fld "date2"
         put empty into fld "date3"
         put empty into fld "date4"
         exit mouseup
      end if
      if fld "temp1" < 0 then
         answer "That date is in the future, so cannot be the start date of the current year. Try again."titled field "fieldboxtitle" of cd "template1"
         hide fld "announce81"
         put empty into fld "temp2"
         put empty into fld "temp1"
         put empty into fld "date2"
         put empty into fld "date3"
         put empty into fld "date4"
         exit mouseup
      end if
     end if
THank you all, once again for everything.
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Problem with date

Post by Klaus »

Code: Select all

...
 convert tdate from system date to long english date
...
YES, SIR! :-)

But you still did not tell us what country (with that system date) you are living in.
CAsba
Posts: 452
Joined: Fri Sep 30, 2022 12:11 pm

Re: Problem with date

Post by CAsba »

Hi Klaus,
I am a native of the United Kingdom of GREAT (get that ?, GREAT) Britain. Not to be confused (under any circumstances - torture, political waffle) with the European Union. A free-born Englishman, travelled the Orient, Africa, the Middle East, and now safely back home, struggling with systemdates and my mobile phone. Back in the day, I was a field helicopter engineer, often in the remotest of locations, in jungles, deserts, oil platforms, and that most perilous space of all, VIP airport lounges - ferrying ministers of state.
I like Livecode, and this forum is most helpful. I hope the above entertains rather that offends.
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10415
Joined: Fri Feb 19, 2010 10:17 am

Re: Problem with date

Post by richmond62 »

A free-born Englishman
I'd be a bit careful where you use that phrase.
stam
Posts: 3209
Joined: Sun Jun 04, 2006 9:39 pm

Re: Problem with date

Post by stam »

CAsba wrote: Thu Aug 21, 2025 3:49 pm I am a native of the United Kingdom of GREAT (get that ?, GREAT) Britain.
As a fellow citizen of the formerly Great Britain:
A source of confusion is that “English” date is actually US, not English date format…
SparkOut
Posts: 2984
Joined: Sun Sep 23, 2007 4:58 pm

Re: Problem with date

Post by SparkOut »

Using "set the useSystemDate to true" in a handler where dates are interpreted generally makes things a lot simpler.

Put one field on a card "fldDate" and get a user to put a date into it in the user's typically accepted format

In a button

Code: Select all

on mouseUp
  set the useSystemDate to true
   put field "fldDate" into tDate
   if tDate is not a date then
     answer "The field contents do not match the date format according to the regional settings of this computer" -- or you're on Windows and the year you've input is prior to 1970, stupid, stupidly unforgiveable bug
   else
     convert tDate to seconds
     answer tDate
   end if
end mouseUp
Assuming you're not falling foul of the inability of LiveCode to interpret a date on Windows prior to the Unix epoch (not a "Windows" bug, it's a "LiveCode" bug) then a user in USA with default regional settings, and a user in UK with default regional settings will both receive the same report of the seconds, despite having input different formats.

The useSystemDate property is reset to default (false) at the end of the handler - you have to specifically set it every time you're in a new scope.

Also, malte's libDate library is still available viewtopic.php?f=16&t=15752#p79627 (github link at end of the thread
https://github.com/derbrill/libdate )
Post Reply