## 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 ...

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

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

### Re: How many days until ...

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 ...

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: 10639
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

### Re: How many days until ...

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 ...

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: 10639
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

### Re: How many days until ...

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 ...

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

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

### Re: How many days until ...

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
Posts: 5740
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

### Re: How many days until ...

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: 10639
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

### Re: How many days until ...

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
Posts: 5740
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

### Re: How many days until ...

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: 10639
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

### Re: How many days until ...

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

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

### Re: How many days until ...

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

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

### Re: How many days until ...

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
Great, please get back here when you get stuck!

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

### Re: How many days until ...

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