How many days until ...

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: Klaus, FourthWorld, heatherlaine, kevinmiller

rjd
Posts: 11
Joined: Thu Aug 29, 2013 11:29 am

How many days until ...

Post by rjd » Thu Jul 12, 2018 1:49 pm

Hi Livecoders - how can I calculate how much time it will be until next Saturday?

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

Re: How many days until ...

Post by Klaus » Thu Jul 12, 2018 1:59 pm

Hi rjd,

there are many ways to do so in LC!
One way:

Code: Select all

...
put the date into tStart
put "7/14/18" into tEnd
convert tStart to seconds
convert tEnd to seconds
put tEnd - tStart into tDuration
answer "Duration until saturday:" && smpte_lite(tDuration)
...

## Will convert seconds to time code HH:MM:SS
function smpte_lite dauer1
  set the numberformat to xx
  put dauer1 div 60 into minu  
  put minu div 60 into stunden 
  put minu mod 60 into minu  
  put dauer1 mod 60 into seku
  return stunden & ":" & minu & ":" & seku
end smpte_lite
Best

Klaus

rjd
Posts: 11
Joined: Thu Aug 29, 2013 11:29 am

Re: How many days until ...

Post by rjd » Thu Jul 12, 2018 2:02 pm

Ah that looks simple enough -- but what if I don't know the date of the 'next' Saturday (or whatever day a user chooses)?

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

Re: How many days until ...

Post by Klaus » Thu Jul 12, 2018 2:16 pm

What do you know about the date in the future? Mind-reading won't work (yet)! :-)
I mean how will the user tell you what he wants?

rjd
Posts: 11
Joined: Thu Aug 29, 2013 11:29 am

Re: How many days until ...

Post by rjd » Thu Jul 12, 2018 2:21 pm

Mind reading would be good to have sometimes when dealing with co-workers =( I'm working on sending reminders on a certain day. If the reminder day is a Saturday (regardless of the date of that Saturday), I was hoping to have a basic countdown timer of sorts to display to the user. Something like ... 4d 3h 24m until Saturday.

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

Re: How many days until ...

Post by Klaus » Thu Jul 12, 2018 2:29 pm

OK, get it, but in the moment I have no quick and simple idea on how to find out how to calculate the "current difference to saturday". Know what I mean?

rjd
Posts: 11
Joined: Thu Aug 29, 2013 11:29 am

Re: How many days until ...

Post by rjd » Thu Jul 12, 2018 3:01 pm

Yes, I know what you mean -- as with the majority of tasks done with Livecode, and as you noted, there are many ways to do something. I'm sure another cool solution will surface here 8)

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

Re: How many days until ...

Post by Klaus » Thu Jul 12, 2018 3:09 pm

This also depends on how your interface will look, resp. how your user will let you know what he wants.

If you provide a mini calendar, then this is a no-brainer. If you let the user enter a day of week, that will be a TAD more complicated and will need a lot of scripting.

Here some food for thought:
In LC we have -> the weekdaynames
This is where you could check the current day of week against the user-entered day

We have -> dateitems
Where we could get the current day of week, read up the entry in the dictionary.

A combination from my last script and these things mentioned above will be able to do what you want to. Can you cut your task into little pieces and solve these according to the things mentioned above?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5632
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How many days until ...

Post by dunbarx » Thu Jul 12, 2018 3:47 pm

Klaus wrote:
Can you cut your task into little pieces and solve these according to the things mentioned above?
How come he gets a pass with this sort of reply, and I don't???

Craig

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

Re: How many days until ...

Post by Klaus » Thu Jul 12, 2018 3:52 pm

dunbarx wrote:
Thu Jul 12, 2018 3:47 pm
How come he gets a pass with this sort of reply, and I don't???
Sorry, don't quite understand this surely funny injection?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5632
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How many days until ...

Post by dunbarx » Thu Jul 12, 2018 4:00 pm

Klaus.

From "Our Klaus"
I hate to break it to you all Klaus is actually a German AI BOT.

It's a Livecode version of Joseph Weizenbaum's Eliza with artificial "Sarcasm" built in and an initial "German Humour" module added.

"Craig" on the other hand is a fork of "Klaus" using recursion and exits the call early when the stack overflows and thus has random questions at the end like "Post Back", "Ask for help?", "More?" this is to hide the fact that this experimental BOT has run out of memory.
XXX

Craig

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

Re: How many days until ...

Post by Klaus » Thu Jul 12, 2018 4:02 pm

Ah, OK, get it, maybe we should really put some more emphasis on the I in AI! :D

rjd
Posts: 11
Joined: Thu Aug 29, 2013 11:29 am

Re: How many days until ...

Post by rjd » Thu Jul 12, 2018 4:03 pm

Thank you for your suggestions and some good hints on how to approach this. I'll give it a go :D

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

Re: How many days until ...

Post by Klaus » Thu Jul 12, 2018 4:08 pm

rjd wrote:
Thu Jul 12, 2018 4:03 pm
Thank you for your suggestions and some good hints on how to approach this. I'll give it a go :D
Great, please get back here when you get stuck!

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4708
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: How many days until ...

Post by jacque » Thu Jul 12, 2018 4:58 pm

The last number in the dateItems is the day of the week. If you are aiming for the next Saturday then convert today's date to dateItems and subtract that number from 7, and add the difference to the last item of today's dateItems. Now you have the date of next Saturday. Convert that back to whatever date format you want.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”