How many days until ...
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
How many days until ...
Hi Livecoders - how can I calculate how much time it will be until next Saturday?
Re: How many days until ...
Hi rjd,
there are many ways to do so in LC!
One way:
Best
Klaus
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
Klaus
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)?
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?
I mean how will the user tell you what he wants?
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.
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?
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
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?
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?
-
- VIP Livecode Opensource Backer
- Posts: 9648
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: How many days until ...
Klaus wrote:
Craig
How come he gets a pass with this sort of reply, and I don't???Can you cut your task into little pieces and solve these according to the things mentioned above?
Craig
-
- VIP Livecode Opensource Backer
- Posts: 9648
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: How many days until ...
Klaus.
From "Our Klaus"
Craig
From "Our Klaus"
XXXI 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.
Craig
Re: How many days until ...
Ah, OK, get it, maybe we should really put some more emphasis on the I in AI!
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
-
- VIP Livecode Opensource Backer
- Posts: 7229
- 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
HyperActive Software | http://www.hyperactivesw.com