Is there a way to display the time left, in hours/minutes/seconds, until a specific future time within the same day?
For example, "There are 6 hours, 32 minutes, and 53 seconds left before your work shift is over"
I keep getting confused when attempting to subtract the current & future minutes since the minute starts over after 60 seconds instead of 100 which would be easier.
Time until...
Re: Time until...
See [url=http://ahkscript.org/docs/commands/EnvSub.htm]EnvSub[/url]
Re: Time until...
I have the following, but I don't know how to put it in a "Hour:Minute:Second" until format.
Code: Select all
Now := A_Now
Future := "20140516163000"
EnvSub, Hours, %Future%, Hours
EnvSub, Minutes, %Future%, Minutes
EnvSub, Seconds, %Future%, Seconds
MsgBox, %Hours% Hours`n%Minutes% Minutes`n%Seconds% Seconds
- FanaticGuru
- Posts: 1908
- Joined: 30 Sep 2013, 22:25
Re: Time until...
Try this:
A dynamic Gui for amusement:
FG
Code: Select all
FutureTime := "17:30:00" ; Each must be two digits and use 24 hour time
FutureTime := A_YYYY A_MM A_DD RegExReplace(FutureTime, "\D")
EnvSub, Seconds, FutureTime, seconds
Seconds := - Seconds
H := Floor(Seconds / 3600), Seconds := Mod(Seconds, 3600)
M := Floor(Seconds / 60), Seconds := Mod(Seconds, 60)
S := Seconds
MsgBox % H (H=1 ? " hour, " : " hours, ") M (M=1 ? " minute, " : " minutes, ") (S ? S : 0) (S=1 ? " second " : " seconds ") "`n`nTill Party Time"
Esc::ExitApp
Code: Select all
FutureTime := "17:30:00" ; Each must be two digits and use 24 hour time
FutureTime := A_YYYY A_MM A_DD RegExReplace(FutureTime, "\D")
Gui, Add, Text, w175 vTime
Gui, Add, Text,, Till Party Time
Gui, Show, AutoSize
SetTimer, Update, 1000
Update:
Seconds =
EnvSub, Seconds, FutureTime, seconds
Seconds := - Seconds
H := Floor(Seconds / 3600), Seconds := Mod(Seconds, 3600)
M := Floor(Seconds / 60), Seconds := Mod(Seconds, 60)
S := Seconds
GuiControl, Text, Time, % H (H=1 ? " hour, " : " hours, ") M (M=1 ? " minute, " : " minutes, ") (S ? S : 0) (S=1 ? " second " : " seconds ")
return
Esc::ExitApp
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
Re: Time until...
This seems to work:
(Similar to FG's)
Code: Select all
Future := 20140516163000
EnvSub, Hours, %Future%, Hours
EnvSub, Minutes, %Future%, Minutes
EnvSub, Seconds, %Future%, Seconds
Seconds -= Minutes * 60
Minutes -= Hours * 60
Hours *= -1, Minutes *= -1, Seconds *= -1
MsgBox, %Hours% Hours`n%Minutes% Minutes`n%Seconds% Seconds
- AlphaBravo
- Posts: 586
- Joined: 29 Sep 2013, 22:59
Re: Time until...
function from FormatTime
Code: Select all
Future := 20140516163000
EnvSub, Future,, Seconds
MsgBox % FormatSeconds(Future)
return
FormatSeconds(NumberOfSeconds){ ; Convert the specified number of seconds to hh:mm:ss format.
time := 19990101 ; *Midnight* of an arbitrary date.
time += %NumberOfSeconds%, seconds
FormatTime, mmss, %time%, mm:ss
return NumberOfSeconds//3600 ":" mmss
}
Re: Time until...
thanks, it hit the spot!
Re: Time until...
Code: Select all
#NoEnv
SetBatchLines, -1
MsgBox, % TimeUntil(16, 30)
ExitApp
; ----------------------------------------------------------------------------------------------------------------------
TimeUntil(Hour, Min := 0, Sec := 0) { ; Hour must be in 24 hour format
TimeInterval := A_YYYY . A_MM . A_DD . SubStr("0" . Hour, -1) . SubStr("0" . Min, -1) . SubStr("0" . Sec, -1)
TimeInterval -= %A_Now%, S
If (TimeInterval > 0) {
; msdn.microsoft.com/en-us/library/bb759980(v=vs.85).aspx
VarSetCapacity(Result, 128, 0)
DllCall("Shlwapi.dll\StrFromTimeInterval", "Str", Result, "UInt", 64, "UInt", TimeInterval * 1000, "Int", 30)
Return Result
}
}
Re: Time until...
tested! yields positive numbers... and thanks for supporting my script habit!
Re: Time until...
I assigned this code to the F4 function key ( added F4:: after #NoEnv ) and have a shortcut in the Windows Startup folder.
It works fine, but only once. Closing the message box and pressing F4 again does nothing.
If my browser is open it works, but pressing F4 a second time drops down the browsing history (the normal F4 function).
How do I make F4 run the script every time?
It works fine, but only once. Closing the message box and pressing F4 again does nothing.
If my browser is open it works, but pressing F4 a second time drops down the browsing history (the normal F4 function).
How do I make F4 run the script every time?
Re: Time until...
That is because of the ExitApp, replace it with Return
Who is online
Users browsing this forum: DecimalTurn, Google [Bot], macromint, peter_ahk and 348 guests