Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: 2 part question about date in a batch file  (Read 16559 times)

0 Members and 1 Guest are viewing this topic.

Salmon Trout

  • Guest
Re: 2 part question about date in a batch file
« Reply #30 on: November 30, 2009, 07:51:39 AM »
Code: [Select]

S:\Test>cscript utc1.wsf
Mon, 30 Nov 2009 14:50:24 UTC

S:\Test>cscript utc1.vbs
30/11/2009 14:50:28


Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: 2 part question about date in a batch file
« Reply #31 on: November 30, 2009, 08:14:26 AM »
Sidewinder, I needed to insert a line thus

<job>

immediately after the first line to avoid this error


Code: [Select]
(15, 4) Windows Script Host: The end tag does not have a corresponding start tag : job

Not sure why you had to insert a job statement immediately after the first line. The error is flagged on line 15, and in fact my posted script had both and opening <Job> and closing </job> statements.

Personally, I prefer not to post scripts that utilize the registry. One small typo can have serious repercussions,  8)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

Salmon Trout

  • Guest
Re: 2 part question about date in a batch file
« Reply #32 on: November 30, 2009, 08:21:28 AM »
Quote from: Sidewinder
Not sure why you had to insert a job statement immediately after the first line. The error is flagged on line 15, and in fact my posted script had both and opening <Job> and closing </job> statements.

When I pasted it into UltraEdit, I had missed the opening < at the very start of the first line. Mea culpa.


JohnBergt

    Topic Starter


    Greenhorn

    Re: 2 part question about date in a batch file
    « Reply #33 on: November 30, 2009, 08:57:26 AM »
    Wow, I didn't realize I was hitting such a sensitive subject.

    The purpose for the time conversion is for doing a back up, like I said in my initial post. There are certain files which have a very specific naming format and this is why I have the DDMMMYY.WXT format. The date is based on UTC date, this is why i asked for the time/date conversion to UTC. I am not averse to using a VB script as opposed to a batch file, i just don't know how to write it. I am open to suggestions.

    this is my batch file as it stands today, this whole thing runs in a hosted environment, so I don't know about access to registries, etc. :

    @echo off
    cls

    setlocal enabledelayedexpansion


    set alphamonth=JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC

    for /f "tokens=%date:~4,2%" %%1 in ("%alphamonth%") do (
        set month=%%1
    )

    set today=%date:~7,2%%month%%date:~-2%


    for /f "tokens=1-4 delims=: " %%1 in ("%time%") do (
        set hour=%%1
        set min=%%2
        if /i %%4 equ pm set /a Hour +=12
    )

    if %hour% lss 10 set hour=0%hour%

    set time=%hour%%min%


    E:
    CD \FCS_FPS\OCA\OPS_BACKUP\TEMP\
    BUTIL -STARTBU @E:\FCS_FPS\OCA\OPS_BACKUP\STARTLST.FIL
    XCOPY E:\FCS_FPS\OCA\OPS\FLTCTRL\DATA\*.DAT E:\FCS_FPS\OCA\OPS_BACKUP\TEMP\ /EXCLUDE:E:\FCS_FPS\OCA\OPS_BACKUP\EXCLUDE.LST
    COPY E:\FCS_FPS\OCA\OPS\FLTCTRL\DATA\%today%*.WXT E:\FCS_FPS\OCA\OPS_BACKUP\TEMP\
    BUTIL -ENDBU @E:\FCS_FPS\OCA\OPS_BACKUP\STARTLST.FIL



    E:\FCS_FPS\OCA\OPS_BACKUP\7ZIP\7ZA A E:\FCS_FPS\OCA\OPS_BACKUP\ZIPS\%today%_%time%.ZIP E:\FCS_FPS\OCA\OPS_BACKUP\TEMP\*.DAT
    E:\FCS_FPS\OCA\OPS_BACKUP\7ZIP\7ZA A E:\FCS_FPS\OCA\OPS_BACKUP\ZIPS\%today%_%time%.ZIP E:\FCS_FPS\OCA\OPS_BACKUP\TEMP\*.WXT

    DEL E:\FCS_FPS\OCA\OPS_BACKUP\TEMP\*.DAT
    DEL E:\FCS_FPS\OCA\OPS_BACKUP\TEMP\*.WXT

    COPY E:\FCS_FPS\OCA\OPS_BACKUP\ZIPS\%today%_%time%.ZIP \\EMGHWP079\E$\FCS_FPS\OCA\OPS_BACKUP\ZIPS\

    Joanlong



      Rookie

      Re: 2 part question about date in a batch file
      « Reply #34 on: November 30, 2009, 09:17:43 AM »

      This is my batch file as it stands today, this whole thing runs in a hosted environment, so I don't know about access to registries, etc. :

      @echo off
      cls

      setlocal enabledelayedexpansion


      set alphamonth=JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC

      for /f "tokens=%date:~4,2%" %%1 in ("%alphamonth%") do (
          set month=%%1
      )

      set today=%date:~7,2%%month%%date:~-2%


      for /f "tokens=1-4 delims=: " %%1 in ("%time%") do (
          set hour=%%1
          set min=%%2
          if /i %%4 equ pm set /a Hour +=12
      )

      if %hour% lss 10 set hour=0%hour%

      set time=%hour%%min%


      E:
      CD \FCS_FPS\OCA\OPS_BACKUP\TEMP\
      BUTIL -STARTBU @E:\FCS_FPS\OCA\OPS_BACKUP\STARTLST.FIL
      XCOPY E:\FCS_FPS\OCA\OPS\FLTCTRL\DATA\*.DAT E:\FCS_FPS\OCA\OPS_BACKUP\TEMP\ /EXCLUDE:E:\FCS_FPS\OCA\OPS_BACKUP\EXCLUDE.LST
      COPY E:\FCS_FPS\OCA\OPS\FLTCTRL\DATA\%today%*.WXT E:\FCS_FPS\OCA\OPS_BACKUP\TEMP\
      BUTIL -ENDBU @E:\FCS_FPS\OCA\OPS_BACKUP\STARTLST.FIL



      E:\FCS_FPS\OCA\OPS_BACKUP\7ZIP\7ZA A E:\FCS_FPS\OCA\OPS_BACKUP\ZIPS\%today%_%time%.ZIP E:\FCS_FPS\OCA\OPS_BACKUP\TEMP\*.DAT
      E:\FCS_FPS\OCA\OPS_BACKUP\7ZIP\7ZA A E:\FCS_FPS\OCA\OPS_BACKUP\ZIPS\%today%_%time%.ZIP E:\FCS_FPS\OCA\OPS_BACKUP\TEMP\*.WXT

      DEL E:\FCS_FPS\OCA\OPS_BACKUP\TEMP\*.DAT
      DEL E:\FCS_FPS\OCA\OPS_BACKUP\TEMP\*.WXT

      COPY E:\FCS_FPS\OCA\OPS_BACKUP\ZIPS\%today%_%time%.ZIP \\EMGHWP079\E$\FCS_FPS\OCA\OPS_BACKUP\ZIPS\

      Here is the Output when the above code is execuded:

      The system cannot find the path specified.
      'BUTIL' is not recognized as an internal or external command,
      operable program or batch file.
      Can't read file: E:\FCS_FPS\OCA\OPS_BACKUP\EXCLUDE.LST

      0 File(s) copied
      The system cannot find the path specified.
      'BUTIL' is not recognized as an internal or external command,
      operable program or batch file.
      The system cannot find the path specified.

      C:\batch>

      Would you show the output when your code is run on your machine?

      I suggest you look at post # 9.

      Or study anything Sidewinder writes.

      You may safely ignore everyone else.

      Salmon Trout

      • Guest
      Re: 2 part question about date in a batch file
      « Reply #35 on: November 30, 2009, 09:24:24 AM »
      Joanlong, aka Billrich, the resident troll.

      gh0std0g74



        Apprentice

        Thanked: 37
        Re: 2 part question about date in a batch file
        « Reply #36 on: November 30, 2009, 09:38:11 AM »
        You may safely ignore everyone else.
        lol , that means including you right?

        Joanlong



          Rookie

          Re: 2 part question about date in a batch file
          « Reply #37 on: November 30, 2009, 09:38:33 AM »
          Joanlong the resident . . . .l.


          The Standard Operating Procedure for the ComputerHope Board:

          When ComputerHope members are unable to answer your questions:

          ComputerHope members call everybody Bad Names.

          « Last Edit: November 30, 2009, 09:57:15 AM by Joanlong »

          Salmon Trout

          • Guest
          Re: 2 part question about date in a batch file
          « Reply #38 on: November 30, 2009, 09:54:46 AM »
          The Standard Operating Procedure for the ComputerHope Board:

          When ComputerHope members are unable to answer your questions:

          ComputerHope members call everybody Bad Names.

          Name calling is the  refuge of the ComputerHope Cowards.

          ...and "ComputerHope Cowards" is a name.

          T.C.



            Beginner

            Thanked: 13
            Re: 2 part question about date in a batch file
            « Reply #39 on: November 30, 2009, 11:48:17 AM »
            JohnBergt - The script you posted in Reply 33 will fail if the month variable contains 08 or 09 (August or September) and, if the time is between 11.59 am and 1.00 pm, the hour will be returned as 24.  Please see my reply #5 posted Nov 26 for amended script.




            Joanlong



              Rookie

              Re: 2 part question about date in a batch file
              « Reply #40 on: November 30, 2009, 01:39:47 PM »

              "I would like to output both the date and time in UTC, instead of local time."

              Sidewinder (Post #27 in this Thread ) gave the perfect answer and we failed to test the code ( Or thank Sidewinder ):


              C:\batch>cscript sidewind.wsf

              Microsoft (R) Windows Script Host Version 5.7
              Copyright (C) Microsoft Corporation. All rights reserved.

               :D
              Mon, 30 Nov 2009 20:34:15 UTC
               :D

                 Thank Sidewinder for their post.
                 

              C:\batch>time /t
              02:34 PM

              C:\batch>


              C:\batch>type sidewind.wsf

              Code: [Select]
              <job id="UTCDateandTime">
                 <script language="JScript">
                    function ConvertDateToUTCString(dtmDate)
                      {
                        var d;                                        //Declare variables.
                        d = new Date(dtmDate);                        //Create Date object.
                        return(d.toUTCString());                      //Convert to UTC string.

                      }
                 </script>

                 <script language="VBScript">
                    strUTC = ConvertDateToUTCString(Now())
                    WScript.Echo strUTC
                 </script>
              </job>


              rem Save the script with a .WSF extension and run from the command prompt:
              rem  cscript sidewind.wsf
              C:\batch>


              p.s.
                 Thank Sidewinder for their post. 
              Sidewinder is far ahead of the rest of us


              http://en.wikipedia.org/wiki/Windows_Script_Host
              « Last Edit: November 30, 2009, 02:08:34 PM by Joanlong »

              Sidewinder



                Guru

                Thanked: 139
              • Experience: Familiar
              • OS: Windows 10
              Re: 2 part question about date in a batch file
              « Reply #41 on: November 30, 2009, 03:21:07 PM »
              JohnBergt ,

              Your batch file should be changed:
              Code: [Select]
              @echo off
              cls

              for /f %%a in ('cscript //nologo scriptname.wsf') do (
                set zipFile=%%a
                )

              setlocal enabledelayedexpansion


              set alphamonth=JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC

              for /f "tokens=%date:~4,2%" %%1 in ("%alphamonth%") do (
                  set month=%%1
              )

              set today=%date:~7,2%%month%%date:~-2%


              for /f "tokens=1-4 delims=: " %%1 in ("%time%") do (
                  set hour=%%1
                  set min=%%2
                  if /i %%4 equ pm set /a Hour +=12
              )

              if %hour% lss 10 set hour=0%hour%

              set time=%hour%%min%

              E:
              CD \FCS_FPS\OCA\OPS_BACKUP\TEMP\
              BUTIL -STARTBU @E:\FCS_FPS\OCA\OPS_BACKUP\STARTLST.FIL
              XCOPY E:\FCS_FPS\OCA\OPS\FLTCTRL\DATA\*.DAT E:\FCS_FPS\OCA\OPS_BACKUP\TEMP\ /EXCLUDE:E:\FCS_FPS\OCA\OPS_BACKUP\EXCLUDE.LST
              COPY E:\FCS_FPS\OCA\OPS\FLTCTRL\DATA\%today%*.WXT E:\FCS_FPS\OCA\OPS_BACKUP\TEMP\
              BUTIL -ENDBU @E:\FCS_FPS\OCA\OPS_BACKUP\STARTLST.FIL



              E:\FCS_FPS\OCA\OPS_BACKUP\7ZIP\7ZA A E:\FCS_FPS\OCA\OPS_BACKUP\ZIPS\%zipFile% E:\FCS_FPS\OCA\OPS_BACKUP\TEMP\*.DAT
              E:\FCS_FPS\OCA\OPS_BACKUP\7ZIP\7ZA A E:\FCS_FPS\OCA\OPS_BACKUP\ZIPS\%zipFile% E:\FCS_FPS\OCA\OPS_BACKUP\TEMP\*.WXT

              DEL E:\FCS_FPS\OCA\OPS_BACKUP\TEMP\*.DAT
              DEL E:\FCS_FPS\OCA\OPS_BACKUP\TEMP\*.WXT

              COPY E:\FCS_FPS\OCA\OPS_BACKUP\ZIPS\%zipFile% \\EMGHWP079\E$\FCS_FPS\OCA\OPS_BACKUP\ZIPS\

              The Windows Script File should be changed to:
              Code: [Select]
              <job id="UTCTime">
                 <script language="JScript">
                    function ConvertDateToUTCString(dtmDate)
                      {
                        var d;                                        //Declare variables.
                        d = new Date(dtmDate);                        //Create Date object.
                        return(d.toUTCString());                      //Convert to UTC string.
                      }
                 </script>

                 <script language="VBScript">
                    strUTC = ConvertDateToUTCString(Now())
                    arrUTC = Split(strUTC, " ")
                   
                    strYR = arrUTC(3)
                    strMon = UCase(arrUTC(2))
                    strDay = arrUTC(1)
                    If Len(strDay) = 1 Then strDay = "0" & strDay
                   
                    arrTime = Split(arrUTC(4), ":")
                    strHH = arrTime(0)
                    strMM = arrTime(1)
                 
                    zipLabel = strYR & strMon & strDay & "-" & strHH & strMM & ".zip"
                    WScript.Echo zipLabel
                 </script>
              </job>

              Save the script file with a WSF extension. Note: the scriptname referenced in the batch file must match the named you save the script as.

              The label of the zip file can be referenced as %zipFile%.

              I left your original batch logic in place while adding the reference to the script file because I couldn't come up with a clean way to resolve %today%*.WXT

              Good luck.  8)

              This is truly an ugly run unit, but since we already used JScript and VBScript in the same WSF file, it's probably not a great leap to wrap everything around some batch code.;D
              « Last Edit: November 30, 2009, 04:43:14 PM by Sidewinder »
              The true sign of intelligence is not knowledge but imagination.

              -- Albert Einstein