3 Replies Latest reply on Oct 4, 2018 12:47 AM by derniwi

    Localisation of Times and Dates in Ivanti DSM escript

    MSeide Rookie

      Hello,

       

      we got many locations with different time zones.

      Using a variable (Type: Datetime) we are defining a local time. Example:: 29.09.2017 20:40:01
      In our escript this times are shown as UTC. Example: 2017-09-29T18:40:09Z
      eScript:
      Set('_ScheduledReboot','%CurrentComputer.Var.CustomSettings.ScheduleReboot%')

       

      We then reformate and localize these using VBS which gets very messy. But we need the time in the respective timezone it was set in as the variable is used to control the reboot of the computer.

       

      Is there a way to do the localization and format in escript? Are there maybe some best practices to do so?

       

      Thank you,

      Michael

        • 1. Re: Localisation of Times and Dates in Ivanti DSM escript
          derniwi Master

          Hello Michael,

           

          it is possible to get the time using WMI and Win32_CurrentTime.

           

          A script may look like this:

          !Initialize variables
          Set('_DATESEPARATOR','-')
          Set('_TIMESEPARATOR',':')
          Set('_DATETIMESEPARATOR',' ')
          Set('_DATE','')
          Set('_WMIDATE','')
          !
          !Get date and time from Win32_CurrentTime using WMI
          WMISimpleQuery('\\.\root\cimv2','Win32_CurrentTime','__CLASS=Win32_LocalTime','_WMIDATE')
          __CLASS
          Day
          Hour
          Minute
          Month
          Second
          Year
          EndProc
          !
          !Format date and time values, 4 digits for the year, two digits for other values
          StrRight('0000%_WMIDATEYEAR%','4','_WMIDATEYEAR')
          StrRight('00%_WMIDATEMONTH%','2','_WMIDATEMONTH')
          StrRight('00%_WMIDATEDAY%','2','_WMIDATEDAY')
          StrRight('00%_WMIDATEHOUR%','2','_WMIDATEHOUR')
          StrRight('00%_WMIDATEMINUTE%','2','_WMIDATEMINUTE')
          StrRight('00%_WMIDATESECOND%','2','_WMIDATESECOND')
          !
          !Create a string in format "YYYY-MM-DD hh:mm:ss"
          Set('_DATE','%_WMIDATEYEAR%%_DATESEPARATOR%%_WMIDATEMONTH%%_DATESEPARATOR%%_WMIDATEDAY%%_DATETIMESEPARATOR%%_WMIDATEHOUR%%_TIMESEPARATOR%%_WMIDATEMINUTE%%_TIMESEPARATOR%%_WMIDATESECOND%')
          

           

          Hope this helps.

           

          You also may have a look at Win32_LocalTime and Win32_UTCTime.

           

          Reagrds

          Nils

          • 2. Re: Localisation of Times and Dates in Ivanti DSM escript
            wardclerk Apprentice

            I've never used the WMI commands in DSM before, even though I've been a NI and DSM admin for 15 years.   I finally have a need to create a date/time variable that I can use elsewhere and tried your WMI commands in a DSM 2018.1 package. 

             

            I get compile errors on the WMISimpleQuery command and even tried creating the command again with the wizard and still get compile errors.

             

            Any more assistance with this?

            • 3. Re: Localisation of Times and Dates in Ivanti DSM escript
              derniwi Master

              Hi,

               

              I've just created the WMISimpleQuery again using DSM 2018.1.

              The problem of the current forum software is that there is no good editor. Copy and paste may work, but you have to check the end of every line and delete unused spaces. Also all the queried properties within "WMISpimleQuery" and "EndProc" need to have one space in front.

               

              Please try it again. ;-)

              WMISimpleQuery('\\.\root\cimv2','Win32_CurrentTime','__CLASS=Win32_LocalTime','_WMIDATE')
               Day
               Hour
               Minute
               Month
               Second
               Year
              EndProc
              

               

              Regards

              Nils