Jump to content

Recommended Posts

I have two variables containing text in the format of time such as timefrom = 06:00 and timeto = 10:00.

I ran a shell enhanced command time /t and stored the result in a variable called currenttime.

Now I require to check if current time is between the two other variables.

Is there a way to do such comparison?

Share this post


Link to post
Share on other sites

I use mysql to do time comparisons, unless you're checking current time of the PC (and want to account for timezone differences) in which case Powershell executing on the remote agent is the best.

Share this post


Link to post
Share on other sites

I finally tried both powershell and shell commands and currently settled on the latter as I found it simpler.

The shell command I am using is if @currenttime@ lss @timefrom (echo 1) else (echo 0)

However I will try to improve it and do the time comparison on a specific server or even sql so that I have to deal less with timezones.

Thanks.

Share this post


Link to post
Share on other sites

Some examples of uptime

((Get-Date) - (Get-CimInstance Win32_OperatingSystem).LastBootUpTime)
((Get-Date) - (Get-CimInstance Win32_OperatingSystem).LastBootUpTime).TotalHours

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...