Page 1 of 1

Convert seconds back to date form

Posted: Wed Jan 10, 2024 12:03 pm
by oldummy
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?

Re: Convert seconds back to date form

Posted: Wed Jan 10, 2024 12:21 pm
by richmond62
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 322010 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.

Re: Convert seconds back to date form

Posted: Wed Jan 10, 2024 1:02 pm
by Klaus
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

Re: Convert seconds back to date form

Posted: Wed Jan 10, 2024 1:19 pm
by richmond62
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.

Re: Convert seconds back to date form

Posted: Wed Jan 10, 2024 1:32 pm
by Klaus
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

Re: Convert seconds back to date form

Posted: Wed Jan 10, 2024 1:59 pm
by richmond62
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.

Re: Convert seconds back to date form

Posted: Wed Jan 10, 2024 2:49 pm
by Klaus
Yeah, got it!

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

Re: Convert seconds back to date form

Posted: Thu Jan 11, 2024 12:35 am
by stam
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

Re: Convert seconds back to date form

Posted: Thu Jan 11, 2024 9:30 am
by oldummy
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.

Re: Convert seconds back to date form

Posted: Fri Jan 12, 2024 12:34 am
by FourthWorld
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.