Count down date
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Count down date
I have fields 'year', 'month', 'date' and 'hour'. What I want is to make count-down script so it will count down the time left to that 'event'. I have no idea how to do this.
Re: Count down date
Hi,
Look up such things as "dateitems", "seconds" and "convert" in the dictionary. Now assemble your disparate data into a form that LC can work with.
Write back if you get stuck. But do try to figure this out before doing so. Date and time stuff is really a lot of fun for a new user.
Craig Newman
Look up such things as "dateitems", "seconds" and "convert" in the dictionary. Now assemble your disparate data into a form that LC can work with.
Write back if you get stuck. But do try to figure this out before doing so. Date and time stuff is really a lot of fun for a new user.
Craig Newman
Re: Count down date
Yeah I looked for "dateItems", "seconds" and "convert", I understand that but when I need to 'subtract' that 'final' time from current time I have problems... Need to set somehow minutes and seconds to max 60, hours to max 24 etc...
-
- Livecode Opensource Backer
- Posts: 447
- Joined: Mon Jan 23, 2012 12:46 pm
Re: Count down date
Have you checked out the scripting conference stack for Date and Time?
http://www.hyperactivesw.com/revscriptc ... ences.html
--Sefro
http://www.hyperactivesw.com/revscriptc ... ences.html
--Sefro
Re: Count down date
Hi croivo,
I use seconds to add or subtract time.
On day have 86400 seconds and that is enough for my needs
Best regards
Jean-Marc
I use seconds to add or subtract time.
On day have 86400 seconds and that is enough for my needs
Best regards
Jean-Marc
https://alternatic.ch
Re: Count down date
Hi.
Now this will only give you integral days, actually taken from the same time in each day. But it obviates leap year issues, and is a great technique to learn. Practice with a few test scripts. Try to work this so that you can, for example, get a counter from noon on Tuesday to dinner on Friday. That sort of thing. Write back if you run into problems.
Craig
What Jean-Marc means is that if you do the math in seconds, all the minute/day stuff goes away. The dateItems is very useful here, going both ways, into and out of seconds.On day have 86400 seconds and that is enough for my needs
Now this will only give you integral days, actually taken from the same time in each day. But it obviates leap year issues, and is a great technique to learn. Practice with a few test scripts. Try to work this so that you can, for example, get a counter from noon on Tuesday to dinner on Friday. That sort of thing. Write back if you run into problems.
Craig
Re: Count down date
Thanks to all for offering your help. Here is what I tried to do: convert both current and "expiry" time to seconds, than subtract these two and convert result to the time. And that kinda works, but it's absolutely not precisely and I know there is much easier and efficient way to do this...
Code: Select all
--CURRENT TIME CONVERT TO SECONDS
put long system time into field "CURRENT"
put field "CURRENT" into ctime
set itemDel to colon
put item 1 of ctime into chours
put item 2 of ctime into cminutes
put item 3 of ctime into cseconds
multiply chours by 3600
multiply cminutes by 60
add chours to cminutes
add cminutes to cseconds
--FINAL TIME CONVERT TO SECONDS
put field "FINAL" into ftime
set itemDel to colon
put item 1 of ftime into fhours
put item 2 of ftime into fminutes
put item 3 of ftime into fseconds
multiply fhours by 3600
multiply fminutes by 60
add fhours to fminutes
add fminutes to fseconds
--SUBTRACT
subtract cseconds from fseconds
convert fseconds to long system time
put fseconds into field "REMAINING"
Re: Count down date
Hi croivo,
For working with date time stuff you Really want to use dateItems.
It will do all the leap year stuff and the days...
Simon
For working with date time stuff you Really want to use dateItems.
It will do all the leap year stuff and the days...
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Count down date
What Simon said. You can calculate offsets outside the normal range automatically - I mean, say the day of the month is 20 and you want to add 20 days, you just add 20 to the day of the month and it works out what day of the next month that is, and adjusts all the rest of the data. Easy.
Re: Count down date
Can somebody give me example, how to 'add 20 days' for example to time I've converted do dateItems? Or subtract...
Re: Count down date
Hi croivo,
a look into the dictionary at "dateitems" might be very enlightening!
...
add 20 to item 3 of tVarWithDateitemsInIt
convert tVarWithDateitemsInIt from dateitems to long system date
answer ("This is 20 days later:" && tVarWithDateitemsInIt)
...
Best
Klaus
a look into the dictionary at "dateitems" might be very enlightening!

...
add 20 to item 3 of tVarWithDateitemsInIt
convert tVarWithDateitemsInIt from dateitems to long system date
answer ("This is 20 days later:" && tVarWithDateitemsInIt)
...
Best
Klaus
Re: Count down date
Ok so I need something like this
but this is not working right...
Code: Select all
on mouseUp
put "15:00" into field "final"
convert field "final" to dateItems
put long system time into field "current"
convert field "current" to dateItems
subtract item 1 of field "current" from item 1 of field "final"
subtract item 2 of field "current" from item 2 of field "final"
subtract item 3 of field "current" from item 3 of field "final"
subtract item 4 of field "current" from item 4 of field "final"
subtract item 5 of field "current" from item 5 of field "final"
subtract item 6 of field "current" from item 6 of field "final"
end mouseUp
Re: Count down date
Sorry, no idea what your script should do?
Re: Count down date
I need to 'count down' the time until some 'event'. So for example now is 15:00, and my 'event' starts in 18:00. I want to count-down time left to that event.
Re: Count down date
So you want to display something like this until 0:00 has been reached:
3:00 ## Start countdown
2:59
2:58
...
0:01
0:00 ## Stop countdown
Right?
3:00 ## Start countdown
2:59
2:58
...
0:01
0:00 ## Stop countdown
Right?