Sign in to follow this  
Followers 0
Gozzgug

Time Calculation Challenge

3 posts in this topic

I have a time calculation challenge for any one of you wizards. I just can't seem to figure this out.

I have a script that take a few parameters from a config file. The parameters are hours and time. Example:

[parameters]

Hours=24

Time=13 ; Time in @HOURS format

The script waits the specified number of "Hours" indicated in the config file. After the "Hours" wait period has expired it then waits until the specified "Time" and executes the command. For the example above it will wait 24 hours and then wait until @HOUR 13(1PM) arrives and execute the command.

I am trying to figure out a way to display the date and time the next action will take place. The biggest hurdle in figuring this out is when the "Hours" cross 12am it's the next day.

A difficult calculation would be this. Say it's 11pm. The config file has these values:

[parameters]

Hours=36

Time=22 ; (10pm)

So when I start the script it's got to add 36 hours to the current time. Then calculate the next time 22(10PM) comes around and display that as a date and time but 10PM would have already passed because it's 11pm when I start the script so it's got to know it's going to be the next day when it executes.

Challenge submitted! I GREATLY thank anyone that can figure this out and will be thoroughly impressed!

Goz

Share this post


Link to post
Share on other sites



#include <Date.au3>
$Hours = 24
$Time = 13

$date = _DateAdd('h',$Hours,_NowCalc())
ConsoleWrite($date & @CRLF)

Dim $MyDate
Dim $MyTime
_DateTimeSplit($date,$MyDate,$MyTime)

$NewDate = $MyDate[1] & "/" & $MyDate[2] & "/" & $MyDate[3] & " " & $Time & ":00:00"

;If specified hour has already passed, add one day
If $MyTime[1] > $Time Then
    $NewDate = _DateAdd('D',1,$NewDate)
EndIf

ConsoleWrite($NewDate & @CRLF)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0