Getting the future 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

Post Reply
Jellobus
Posts: 317
Joined: Tue Dec 10, 2013 2:53 pm

Getting the future date

Post by Jellobus » Wed Sep 07, 2022 10:03 pm

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Getting the future date

Post by dunbarx » Wed Sep 07, 2022 10:15 pm

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
Last edited by dunbarx on Wed Sep 07, 2022 10:20 pm, edited 1 time in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Getting the future date

Post by dunbarx » Wed Sep 07, 2022 10:17 pm

If you want a silly ride concerning dates, check out;
https://forums.livecode.com/viewtopic.p ... ng#p138530

Craig

stam
Posts: 3061
Joined: Sun Jun 04, 2006 9:39 pm

Re: Getting the future date

Post by stam » Wed Sep 07, 2022 10:38 pm

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.

Jellobus
Posts: 317
Joined: Tue Dec 10, 2013 2:53 pm

Re: Getting the future date

Post by Jellobus » Thu Sep 08, 2022 1:44 am

It helps :) Thank you!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Getting the future date

Post by dunbarx » Thu Sep 08, 2022 1:58 am

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

Post Reply