Page 1 of 1
Getting the future date
Posted: Wed Sep 07, 2022 10:03 pm
by Jellobus
Hi,
How can I get the future date?
Let's say today is Aug 30. What date can it be after 24 hours/86400sec?
It can be Aug 31 or Sep 1st. Is there a way to get the correct future date?
I tried "convert the second+86400 to the date," but it did not work. Please advice.
Thanks for your time!
Louis
Re: Getting the future date
Posted: Wed Sep 07, 2022 10:15 pm
by dunbarx
Hi.
Read up in the dictionary about the "dateItems". This little gadget has it all. For your question, you would "convert" a dateItem string to whatever you want to into, say, the long date.(pseudo)
Code: Select all
get the long date
convert it to dateitems
add someValueOrOtherToOneOfTheItemsInThedateItemsString
convert it from dateItems to long date and long time
Other ways, if you only want the current date after 86400 seconds, is something like:
Code: Select all
on mouseup
get the seconds
add 86400 to it
convert it to long date
answer it
end mouseup
There are a lot of ways to do this in LC.
Craig
Re: Getting the future date
Posted: Wed Sep 07, 2022 10:17 pm
by dunbarx
If you want a silly ride concerning dates, check out;
https://forums.livecode.com/viewtopic.p ... ng#p138530
Craig
Re: Getting the future date
Posted: Wed Sep 07, 2022 10:38 pm
by stam
I'd go with Craig's suggestion of using dateItems, very useful for this... worth looking it up in the dictionary and searching online for examples
dictionary wrote:A list in dateItems format can have values beyond the expected range for any given item (e.g. a day of the month of less than 1 or greater than the number of days in that month) without causing issues when converting it again later, outputting a date adjusted for such an irregularity. For example, the date 4 weeks from today can be determined by adding 28 to the third item (i.e. the day of the month) and then re-converting.
Re: Getting the future date
Posted: Thu Sep 08, 2022 1:44 am
by Jellobus
It helps

Thank you!
Re: Getting the future date
Posted: Thu Sep 08, 2022 1:58 am
by dunbarx
Stam, et. al.
An even nicer thing about dateItems is that one can do anything one feels like with it:
Code: Select all
on mouseUp
get the date
convert it to dateItems
add 2000 to item 3 of it -- add 2000 days to item 3, the day number
convert it to long date
answer it
end mouseUp
You get a date near the end of the decade. DateItems cares nothing about its contents being a legitimate date. It only holds the math and does the math.
Craig