AutoHotKey Subtraction and Return Variable - autohotkey

I have started to create a script for WhatsApp web, it is to change a group name and the number of days left till something. However, I want to be able to run the script each day so it takes away one day.
I'm unsure how to do subtraction or how to go about to do this, does AutoHotKey have a return function so I can return the variable at the end.
let's say the number of days is 90
so when I run the script next it will be 89
then the next day after when I run, it will be 87
I'm very new to AutoHotKey and still learning about it but loving it so far.

; FormatTime transforms a YYYYMMDDHH24MISS timestamp into the specified date/time format.
FormatTime, Date, CurrentDate, YYYYMMDD
Expires := 20170611 ; 06/12/2017
; Subtract Date timestamp from Expires timestamp
EnvSub, Expires, CurrentDate, days
; The result is stored in Expires
Msgbox % Expires " days left till ..."
https://autohotkey.com/docs/commands/FormatTime.htm
To run the script each day, create a shortcut of it in your startup folder, or use SetTimer.

Time in days, hours and minutes left till a specific time:
FormatTime, Date, CurrentDateTime, YYYYMMDDHHMI
expires := 201706111537 ; 06/11/2017 15:37
; time left in minutes:
expires_minutes := expires
EnvSub, expires_minutes, CurrentDateTime, minutes
; time left in hours:
expires_hours := expires_minutes
EnvDiv, expires_hours, 60
; time left in days:
expires_days := expires_minutes
EnvDiv, expires_days, (24 * 60)
; rest of the division in hours:
rest_hours := expires_hours - (expires_days * 24)
; rest of the division in minutes:
rest_minutes := expires_minutes - (expires_hours * 60)
Msgbox %expires_days% days, %rest_hours% hours and %rest_minutes% minutes left till ...

Related

Coldfusion calculate seconds in days, hours, min

I want to convert seconds to days, hours and minutes
Currently, it works just for hours and minutes but not for days. Can you please support me tell me what I did wrong:
<cfscript>
seconds = '87400';
midnight = CreateTime(0,0,0);
time = DateAdd("s", seconds, variables.midnight);
date= xxxxxxxxxxxxxxxxxxxxx???
</cfscript>
<cfoutput>
#DateFormat(variables.date, 'd')# not working
#TimeFormat(variables.time, 'HH:mm')#
</cfoutput>
For the value 87400 the expected result is
1 Days, 0 hours, 16 minutes
If I take 94152 seconds it will be:
1 days, 3 hours, 22 minutes
The only issue i have is to get the correct days ... hours and minutes are diplayed but not the correct days
thank you for all the support
A simple way to calculate the intervals is by taking advantage of the modulus operator:
totalSeconds = 94152;
days = int(totalSeconds / 86400);
hours = totalSeconds / 3600 % 24;
minutes = totalSeconds / 60 % 60;
seconds = totalSeconds % 60;
For 94152 seconds, the results would be:
Interval
Value
DAYS
1
HOURS
2
MINUTES
9
SECONDS
12
TOTALSECONDS
94152
demo trycf.com
I understand from your question that you don't need to get a certain date and time along a timeline, but convert a total amount of seconds in days, hours and minutes. To do that you don't necessary need to use cfml time and date functions like CreateTime() or DateAdd(). You just may need these in order to get a reference point of time or date along a timeline, which doesn't seem to be the case, otherwise you would know the value of your starting date variable. Thus, you can solve this with plain rule of three. There may be simpler methods, so I'm posting an alternative only.
We know that:
60 seconds is equivalent to 1 minute
60 minutes is equivalent to 1 hour
24 hours is equivalent to 1 day
Thus, your calcualtion within cfml could be like so:
<cfscript>
//Constants for calculation
secondsPerDay= 60*60*24;
secondsPerHour= 60*60;
secondsPerMinute= 60;
//Seconds to convert
secondsTotal=87400;
// temp variable
secondsRemain= secondsTotal;
days= int( secondsRemain / secondsPerDay);
secondsRemain= secondsRemain - days * secondsPerDay;
hours= int( secondsRemain / secondsPerHour);
secondsRemain= secondsRemain - hours * secondsPerHour;
minutes= int( secondsRemain / secondsPerMinute);
secondsRemain= secondsRemain - minutes * secondsPerMinute;
writeoutput( "#secondsTotal# seconds are: #days# days, #hours# hours, #minutes# minutes and #secondsRemain# seconds." );
</cfscript>
That outputs:
87400 seconds are: 1 days, 0 hours, 16 minutes and 40 seconds.

Tableau - How to calculate date/time difference and result in full date/time?

I'm trying to calculate a difference between connection time and disconnected time. See image below. But DATEPART formula that I'm using only allows me to use one parameter (hour, minute, second,...)
However, as in the image, I have an ID where disconnection at 3/1/17 2:35:22PM and connection back at 3/2/17 1:59:38 PM
Ideal Response: 23 hours, 24 minutes and 16 seconds
but using the formula:
ZN(LOOKUP(ATTR(DATEPART('minute', [Disconnected At])),-1)-(ATTR(DATEPART('minute', [Connected At]))))
it isn't doing the trick.
Could someone help me to achieve my ideal response? Or similar result that would give me the completeness of date and time?
Thank You
Tableau ScreenShot
Use DATEDIFF by seconds between your two dates. Then create a calc field as follows:
//replace [Seconds] with whatever field has the number of seconds in it
//and use a custom number format of 00:00:00:00 (drop the first 0 to get rid of leading 0's for days)
IIF([Seconds] % 60 == 60,0,[Seconds] % 60)// seconds
+ IIF(INT([Seconds]/60) %60 == 60, 0, INT([Seconds]/60) %60) * 100 //minutes
+ IIF(INT([Seconds]/3600) % 24 == 0, 0, INT([Seconds]/3600) % 24) * 10000 //hours
+ INT([Seconds]/86400) * 1000000 // days
for more information, check out this blog post where I got this from. http://drawingwithnumbers.artisart.org/formatting-time-durations/

How to convert an official DateTime to the astronomically exact DateTime?

I've been trying to figure out how to convert a birthday (DateTime) to the astronomically "exact" DateTime value. Timezone: UTC+1.
Example:
My friend was born 1984-01-27 11:35
1984 is a leap year. But 1700, 1800 and 1900 were not leap years. So until the 29. February of the year 2000 we are running behind in astronomoically exact time. In 1984 we are "almost" one day behind. So the astronomoically exact time would be after the official DateTime of my friend's birth, right?
These are the Gregorian calendar tweaks I know of:
Every year has 365 days
Every 4th year is a leap year (= has 366 days instead of 365)
Every 100th year is not a leap year
Every 400th year is a leap year (dispite the previous rule)
The additional day is added at the end of February (February has 29 days in a leap year)
Astronomoically a year has 365,2422 days.
Which means that a day is 24,0159254794 hours long.
A time value where the official and astronomoical times are "exactly" the same would be 2000-03-01T00:00:00, right?
So one would need to figure out how big the discrepancy between the official time and the astronomically exact time is at a given official time.
I've been thinking about it for hours, until my head started hurting. I figured I'll share my headache with you. Maybe you guys know any time library that can calculate this?
I came up with a "solution" that seems to be fairly accurate enough. Here's what it does:
The method starts at 1600-03-01T00:00. 18 years after Pope Gregor XIII. (after whom our Gregorian Calendar system is named) fixed the Julian Calendar (named after Julius Caesar) in 1582 by declaring that after the 4th October (Thursday) the next day would be the 15th October (Friday) - so there is actually no 5th to 14th October 1582 in history books - and also adding the 100th and 400th year rules to the calendar system.
The method sums up the discrepany between the official date and the exact date until the given date is reached.
At leap years it applies the correction added by Pope Gregor XIII. It does so at the end of February.
Code:
public static DateTime OfficialDateTimeToExactDateTime(DateTime dtOfficial)
{
const double dExactDayLengthInHours = 24.0159254794;
DateTime dtParse = new DateTime(1600, 3, 1, 0, 0, 0);
double dErrorInHours = 0.0;
while (dtParse <= dtOfficial)
{
dErrorInHours += dExactDayLengthInHours - 24;
dtParse = dtParse.AddDays(1);
if (dtParse.Month == 3 && dtParse.Day == 1 &&
((dtParse.Year % 4 == 0 && dtParse.Year % 100 != 0) ||
(dtParse.Year % 400 == 0)) )
{
dErrorInHours -= 24;
}
}
dErrorInHours += ((double)dtOfficial.Hour + (double)dtOfficial.Minute / 60 + (double)dtOfficial.Second / 3600) * (dExactDayLengthInHours - 24);
return dtOfficial.AddHours(dErrorInHours * -1);
}
I did some sanity testing:
If you pass a date before 2000-03-01T00:00 you get a negative correction. Because we measure days shorter as they in fact are.
If you pass a date after 2000-03-01T00:00 you get a positive correction. This is because 2000 is a leap year (while 1700, 1800 and 1900 are not), but the correction applied is too big. In 24 x 400 = 4800 years the correction would be about one day too big. So in the year 1600 + 4800 = 6400 (if man is still alive), you would need to delcare 6400 a non-leap year, despite the rules of the Gregorian calendar.

VBSCRIPT - Have Current Time and a Duration and want to calculate start time based on these values

Example:
Time = 09:41:46
Duration = 0:00:17 (IE 17 seconds)
Start Time = Time - Duration
Clearly I can't just break this up into hours minutes and seconds and do a basic minus operation given the 60 minute hour and 60 second minute etc.
Can't seem to get my head around how to calculate this and hoping someone has come across this before :).
You can use the DateAdd function.
For example, this will subtract 17 seconds from the specified date/time.
DateAdd("s", -17, "1/1/2013 09:41:46")
Try this
Time = 09:41:46
Duration = 0:00:17
Start_Time = FormatDateTime(Time - Duration, 3)
wscript.echo hour(Start_Time)
wscript.echo minute(Start_Time)
wscript.echo second(Start_Time)
References:
https://www.w3schools.com/asp/asp_ref_vbscript_functions.asp#date

How can I convert a timestamp to a user-friendly time string

I want to be able to present "today" and "yesterday" for recent dates in my application. I've got a date formatter in use currently to show dates (retrieved from data records) and will keep using this for anything more than a couple of days old. I just really like the way the SMS app in the iPhone shows dates for recent messages and would like to emulate this.
The time-stamps that I have to work with are generated on a server that the phone downloads the data records from. All times are therefore generated at UTC (i.e. GMT) time.
I've been fiddling about with this for a while the solutions I've devised just seem horribly long-winded.
Can anyone suggest how to implement a method that could do this?
Cheers - Steve.
If this is a web app, you might find PrettyDate useful. I made a vb.net implementation that could easily be converted to another language:
Public Function formatDate(ByVal time As DateTime) As String
Dim datediff As TimeSpan = Now.Subtract(time)
Dim days As Integer = datediff.TotalDays
If days < 1 Then
Dim seconds As Integer = datediff.TotalSeconds
Select Case seconds
Case 0 To 60
Return "just now"
Case 61 To 120
Return "1 minute ago"
Case 121 To 3600
Return Math.Floor(seconds / 60) & " minutes ago"
Case 3601 To 7200
Return "1 hour ago"
Case 7201 To 86400
Return Math.Floor(seconds / 3600) & " hours ago"
End Select
ElseIf days < 31 Then
Select Case days
Case 1
Return "yesterday"
Case 2 To 7
Return days & " days ago"
Case Is > 7
Return Math.Ceiling(days / 7) & " weeks ago"
End Select
Else : Return time.ToString("MM/dd/yyyy")
End If
End Function