Convert seconds back to date form

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

Post Reply
oldummy
Posts: 78
Joined: Mon Jun 13, 2016 3:21 pm

Convert seconds back to date form

Post by oldummy » Wed Jan 10, 2024 12:03 pm

If I recorded the seconds one day into a fld, then wanted to check what day I recorded it a month later, can I use that value to convert back to the original date form when it was recorded?

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Convert seconds back to date form

Post by richmond62 » Wed Jan 10, 2024 12:21 pm

I have a feeling that would be extremely awkward as months have variable lengths, and there are about 15 different calendars current in the world (For the sake of argument, LiveCode has no encoding for the Shakabda clandar (expired)), and even some of those calendars are determined not in seconds, but is subdivisions of muhurtas.

Rabbit hole this way: https://en.wikipedia.org/wiki/Hindu_calendar

HOWEVER, if you want to be fairly pedestrian and use the Gregorian calendar (!), you COULD work things out be working backwards from today's date and time.
-
SShot 2024-01-10 at 13.16.59.png
SShot 2024-01-10 at 13.16.59.png (12.7 KiB) Viewed 300330 times
-
Taking into account that LiveCode (which is made in Scotland) by default uses the North American date format, which for some reason known only to the colonists, puts the day number AFTER the month number.

You would then have to do all sorts of complex calculations: first by calculating what the date & time by the Gregorian calendar is in terms of second, subtracting the seconds from your reading, and then reversing the calculation to end up with the date and time you wanted.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Convert seconds back to date form

Post by Klaus » Wed Jan 10, 2024 1:02 pm

oldummy wrote:
Wed Jan 10, 2024 12:03 pm
If I recorded the seconds one day into a fld, then wanted to check what day I recorded it a month later, can I use that value to convert back to the original date form when it was recorded?
Yes! :-)

Code: Select all

...
put fld "the stored seconds" into tSecs
convert tSecs to ***
## *** Select one of these options:
## date
## system date
## long date
## long system date
answer tSecs
...
And look up "convert" (and maybe "dateitems", VERY handy for manipulating dates!) in the dictionary.

Best

Klaus

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Convert seconds back to date form

Post by richmond62 » Wed Jan 10, 2024 1:19 pm

Yes, of course, Klaus.

But the OP did not say which calendar he was intending to use.

The current Hebrew year, AM 5784, began at sunset on 15 September 2023 Gregorian current and will end at sunset on 2 October 2024 Gregorian current.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Convert seconds back to date form

Post by Klaus » Wed Jan 10, 2024 1:32 pm

richmond62 wrote:
Wed Jan 10, 2024 1:19 pm
But the OP did not say which calendar he was intending to use.
Yes, and that made me naively think that he, like me, just does not consider this stuff, Captain Cumbersome! :D :D :D

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Convert seconds back to date form

Post by richmond62 » Wed Jan 10, 2024 1:59 pm

Round these parts (Bulgaria), the local church being bloody-minded, while being Orthodox uses the Gregorian (Catholic) calendar to calculate most Christian festivals (such as Christmas), but uses the Julian calendar to calculate Easter; which, as a person who runs a private school and has to work out the 'academic' calendar evey year, is a serious pain-in-the bum: especially as some of my pupils are Catholic (so celebrate Easter using the Gregorian calendar), or Jewish (who don't celebrate Easter, but do celebrate their own special day,s, or Muslims (who use the Islamic calendar which is 354/5 days long (so, the 2 Eids ( that's "Bairam" round these parts) precess through the Gregorian/secular year).

So, when a parent come in and says, "Why don't you have 3 days off for Kotch Bairam (Eid al-Adha)?" instead of saying, "Personally I feel that slitting a sheep's throat in the middle of the road a bit 'off'." I have to do alsorts of 'funny' calculations to readjust my school calendar, and not rub either the Christians or the Jews up the wrong way.

And as oldummy has not stated his/her country of residence and/or origin, it is both unwise and distinctly ethnocentric to assume which calendar they might be using.

HOWEVER, as all the calendars in use worldwide are just a matter of Mathematics, conversion both between calendars and between seconds (or whatever) and days, and so on, are perfectly doable in LiveCode.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Convert seconds back to date form

Post by Klaus » Wed Jan 10, 2024 2:49 pm

Yeah, got it!

If there is a bulgarian version of an operating system, what would LCs "put the SYSTEM date" then possibly return? 8)

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Convert seconds back to date form

Post by stam » Thu Jan 11, 2024 12:35 am

oldummy wrote:
Wed Jan 10, 2024 12:03 pm
If I recorded the seconds one day into a fld, then wanted to check what day I recorded it a month later, can I use that value to convert back to the original date form when it was recorded?
Funnily enough I needed this a few days ago and use this function:

Code: Select all

function dateTimeFromSeconds pSeconds 
-- return system date in item 1, system time in item 2
    local tDate, tTime
    convert pSeconds from seconds to dateItems
    put pSeconds into tDate
    put pSeconds into tTime
    convert tDate from dateitems to system date
    convert tTime from dateitems to system time
    return tDate & comma & tTime
end dateTimeFromSeconds
The function returns a list where item 1 is the system date and item 2 is the system time
HTH
Stam

oldummy
Posts: 78
Joined: Mon Jun 13, 2016 3:21 pm

Re: Convert seconds back to date form

Post by oldummy » Thu Jan 11, 2024 9:30 am

Ahh. Thank you all for the replies. I'm still not sure if I want to store these dates using the seconds but now I can. Thanks to all again.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9842
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Convert seconds back to date form

Post by FourthWorld » Fri Jan 12, 2024 12:34 am

Seconds or InternetTime are the two formats especially useful if you need to support teams in different time zones, as they are based off of GMT and can be converted to local time easily.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”