Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Days Until...

Aug
1,917
68
Here is an alias to determine how many days there are until a certain date;
Code:
alias daysuntil=`type https://days.to/%1-%2/%3 | tpipe /simple=16 | ffind /k/m/t"There are"`

Thus;
Code:
daysuntil 20 December 2016

will return
Code:
There are 34 days  until 20th December 2016

One could also do this using TCC internal functions and variables
Code:
echo %@eval[%@doy[%_year-12-20] - %_doy]

This returns 35.

Interesting how there is one day difference. Must be a time zone adjustment.

These are unpolished, and just demonstrations.

Joe
 
The @AGEDATE and @MAKEAGE functions can be used here as well. Your TCC example only works if the delta is less than a year.
Code:
echo %@eval[%@makeage[12-25-2016] - %@makeage[%_date,%_time]]
33079960000000

echo %@agedate[%@eval[%@makeage[12-25-2016] - %@makeage[%_date,%_time]],6]
1601-039,06:06:47.000

The first returns the number of hectonanoseconds between now and Christmas. A hectonanosecond is 100 nanoseconds.
And the second returns that delta converted to ISO date format 6.

The trick is turning that into something that makes sense to a human. For example, years, months, days, hours, minutes, seconds.
Computing years and months is tricky due to leap years and inconsistent days per month.
And if you are mid-month (today is November 16) is 1 month equal to 30 days? Or do you forgo months and just show days?

This script will show days, hours, minutes, & seconds until Christmas
Code:
setlocal
set interval=%@eval[(%@makeage[12-25-2016] - %@makeage[%_date,%_time])]
set days=%@int[%interval / 10000000 / 60 / 60 / 24] 
set interval=%@eval[%interval - %days * 24 * 60 * 60 * 10000000]
set hours=%@int[%interval / 10000000 / 60 / 60]
set interval=%@eval[%interval - %hours * 60 * 60 * 10000000]
set mins=%@int[%interval / 10000000 / 60]
set interval=%@eval[%interval - %mins * 60 * 10000000]
set secs=%@int[%interval / 10000000]
echo Days until Christmas:
echo Days: %days
echo Hours: %hours
echo Minutes: %mins
echo Seconds: %secs
endlocal

You could also parse the ISO output. In the above example, the year is 1601 and the day is 39. So you need to subtract 1601 to get year relative to 0 and subtract 1 from the day to start numbering from 0. That would give years = 0, days = 38, hours:mins:secs = 6 : 6 : 47
Code:
setlocal
set interval=%@agedate[%@eval[%@makeage[12-25-2016] - %@makeage[%_date,%_time]],6]
set years=%@eval[%@word["-",0,%interval] - 1601]
set days=%@eval[%@word["-,",1,%interval]  - 1]
set hours=%@eval[%@word[",:",1,%interval]]
set mins=%@eval[%@word[",:",2,%interval]]
set secs=%@eval[%@word[",:",3,%interval]]
echo Time until Christmas:
echo Years: %years
echo Days: %days
echo Hours: %hours
echo Minutes: %mins
echo Seconds: %secs
endlocal
 
The @AGEDATE and @MAKEAGE functions can be used here as well. Your TCC example only works if the delta is less than a year.
Or @DATE and @MAKEDATE. The range is smaller, but the unit is a whole lot more intuitive....
 
Back
Top