Avatar of sirbounty
sirbountyFlag for United States of America asked on

modify function to get 24-hour clock

I have this function to schedule a job on servers all over the world approximately 3 hours from 'now'.
Usage for the function:
      arrStart=Split(TimeToRun(objItem.CurrentTimeZone)," ")
      StartDate=arrStart(0)
      StartTime=arrStart(1)

Problem is, due to the 24-hour clock used within schtasks, it's not hitting it correctly in some instances (2am instead of 2pm/1400).
Anyone willing to feed this thing some brain-power?
Function TimeToRun(tz)
    Const OffSet=180
    Set colItems = objWMI.ExecQuery("Select * From Win32_LocalTime")
    For Each objItem in colItems
      With objItem
        LocalDateString=.Month & "/" & .Day & "/" & .Year & " " & .Hour & ":" & .Minute & ":" & .Second
      End With
    Next
 
    GMT=DateAdd("n",-(tz),LocalDateString)
    NewGMTtime=DateAdd("n",OffSet,GMT)
    TimeToRun=DateAdd("n",tz,newGMTTime)
  End Function

Open in new window

VB Script

Avatar of undefined
Last Comment
sirbounty

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
purplepomegranite

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
sirbounty

No, I don't think format is a valid internal vbs function, is it?
At any rate, formatdatetime is - and I got it to work by using:
      StartTime=formatdatetime(arrStart(1) & " " & arrStart(2),vbShortTime) & ":00"
(vbShortTime seems to be the only one returning 24-hour clock, so I have to force the seconds).
purplepomegranite

Oops, I was in VB mode... I always forget format isn't available in VBS.  Glad you got it to work though!
ASKER
sirbounty

Yeah - me 2. :o)
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy