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 16545 times)

0 Members and 1 Guest are viewing this topic.

Joanlong



    Rookie

    Re: 2 part question about date in a batch file
    « Reply #15 on: November 29, 2009, 06:40:43 PM »
    then , Miss ,  can you show a complete batch solution to do both part 1 and 2?

    Part 2 is such a minor problem, we will leave as an exercise  for the original Poster.

    For example,  Central Time is five hours behind ( depending summer or winter ).

    gh0std0g74



      Apprentice

      Thanked: 37
      Re: 2 part question about date in a batch file
      « Reply #16 on: November 29, 2009, 06:54:47 PM »
      Part 2 is such a minor problem, we will leave as an exercise  for the original Poster.

      For example,  Central Time is five hours behind ( depending summer or winter ).
      can you at least show pseudocode of how you are going to determine if you are in "Central Time" whatever you call it, or do addition or subtraction to this "five hours"? Or how to determine whether OP is in summer or winter ? Please, miss genius, I doubt OP knows how to do all these PROGRAMMATICALLY. Since you know how, please show us, or is it you are just talk and no show?

      Salmon Trout

      • Guest
      Re: 2 part question about date in a batch file
      « Reply #17 on: November 30, 2009, 03:28:26 AM »
      You tell him, Ghostdog!

      gh0std0g74



        Apprentice

        Thanked: 37
        Re: 2 part question about date in a batch file
        « Reply #18 on: November 30, 2009, 04:12:28 AM »
        You tell him, Ghostdog!

        lol , no i am not in the mood. Besides, i am not the one who knows how to do it in batch :)
        he(or she) says its a minor issue and seem to know how to do it, so i will wait for his(her) batch solution.

        Salmon Trout

        • Guest
        Re: 2 part question about date in a batch file
        « Reply #19 on: November 30, 2009, 04:46:09 AM »
        lol , no i am not in the mood. Besides, i am not the one who knows how to do it in batch :)
        he(or she) says its a minor issue and seem to know how to do it, so i will wait for his(her) batch solution.

        No - "You tell him!" is a British colloquialism meaning "Bravo for putting him in his place!". Said with the emphasis on "tell".

        BC_Programmer


          Mastermind
        • Typing is no substitute for thinking.
        • Thanked: 1140
          • Yes
          • Yes
          • BC-Programming.com
        • Certifications: List
        • Computer: Specs
        • Experience: Beginner
        • OS: Windows 11
        Re: 2 part question about date in a batch file
        « Reply #20 on: November 30, 2009, 05:05:59 AM »
        performing Date manipulation in Batch has many flaws:

        First: a string has to be parsed- usually from date /t or %date%. Why is this a problem? Because exactly what and how it is parsed depends entirely on regional options, none of which can even be inferred. for example- how do you know wether "Wed 12/01/2009" is January 12th (DD/MM/YYYY) or December 1st? (MM/DD/YYYY)? Logically- we can see that it is the first option, since January 12th 2009 was a Monday. But there is no way to acquire this information programmatically via batch code.

        Visual Basic Script uses the OLE automation Variant Date manipulation Functions to perform it's Date manipulation. These routines "know" what the systems regional settings are and know how to parse dates. Date is, a different variant Subtype (and in full blown VB can be used as a explicit type as well) and for good reason. Handling Dates as strings is playing with fire; you simply cannot predict for every possible arrangement of time and date information. If the regional options are set to display as "DD/HH/MM/YYYY/SS" (day/Hour/Minute/Year/Second) then the user should *censored* well be able to input their PREFERRED entry style into scripts that accept date entry; that's what the regional settings are for. There should be no requirement to "enter in this specific format" because "this specific format" should be the bloody regional settings format as set by the USER for purposes of DATE ENTRY.

        Additionally, I know why Salmon Trout, at least, would be so animate about this type of thing. the UK uses a different date format by default, and every time one of us USians decides that the default North American format is "good enough" for a batch it's like a little slap in the face, especially when tools such as VBScript are so widely available that solve the issue entirely. And really- it doesn't matter the context- there is NO excuse for ignoring the OS preferences as set by the user.

        A analogous situation could be seen with batch when it was only a "pure DOS" type solution, without command extensions. It could NOT do arithmetic at  all.

        Did people write batch files to perform arithmetic and parse date strings? No. Because it was bloody hard and not worth the time; when people needed to do math like this they ALWAYS resorted to another solution. This should be the case for performing date manipulation with Batch. If there will be any sort of deployment of a batch file across a company or especially in separate countries, the "good enough" string parsing solutions in batch will not be acceptable, and something else will need to be devised. How much batch code will be necessary simply to properly parse a date string using regional options? None- the problem is intractable in batch code because there is no way to acquire the regional format and there is surely no way to properly use that string (if it is even acquirable) to parse out the components of a date /t output.

        The best compromise  solution would be to write a VBScript to perform generic date manipulations and ignore performing such operations in batch at all.
        I was trying to dereference Null Pointers before it was cool.

        gh0std0g74



          Apprentice

          Thanked: 37
          Re: 2 part question about date in a batch file
          « Reply #21 on: November 30, 2009, 05:32:17 AM »
          No - "You tell him!" is a British colloquialism meaning "Bravo for putting him in his place!". Said with the emphasis on "tell".

          sorry, english is not my native language. what is put him in his place??

          Salmon Trout

          • Guest
          Re: 2 part question about date in a batch file
          « Reply #22 on: November 30, 2009, 05:40:53 AM »
          sorry, english is not my native language. what is put him in his place??

          If someone says something stupid, and you reply in a way that shows how stupid that person is, that is "putting that person in his place".


          BC_Programmer


            Mastermind
          • Typing is no substitute for thinking.
          • Thanked: 1140
            • Yes
            • Yes
            • BC-Programming.com
          • Certifications: List
          • Computer: Specs
          • Experience: Beginner
          • OS: Windows 11
          Re: 2 part question about date in a batch file
          « Reply #23 on: November 30, 2009, 05:45:57 AM »
          sorry, english is not my native language.

          really?

          Could have fooled me!  :)
          I was trying to dereference Null Pointers before it was cool.

          Salmon Trout

          • Guest
          Re: 2 part question about date in a batch file
          « Reply #24 on: November 30, 2009, 05:48:29 AM »

          gh0std0g74



            Apprentice

            Thanked: 37
            Re: 2 part question about date in a batch file
            « Reply #25 on: November 30, 2009, 06:19:28 AM »
            really?

            Could have fooled me!  :)
            lol, yes, english is not my native language. Only after years of writing/practicing with it that i can write half as good as you(or anyone else) :)

            gh0std0g74



              Apprentice

              Thanked: 37
              Re: 2 part question about date in a batch file
              « Reply #26 on: November 30, 2009, 06:21:19 AM »
              If someone says something stupid, and you reply in a way that shows how stupid that person is, that is "putting that person in his place".
              i see. lol i get it now. I thought you are telling me to write the code and show "him". 

              Sidewinder



                Guru

                Thanked: 139
              • Experience: Familiar
              • OS: Windows 10
              Re: 2 part question about date in a batch file
              « Reply #27 on: November 30, 2009, 07:14:29 AM »
              VBScript may not be the best tool in this situation as there is no native UTC support. JScript on the otherhand has a few UTC methods, one of which may be helpful. JScript, along with it's companion VBScript gets installed when Windows in installed (post Win95). By creating a Windows Script File (WSF), it is possible to use the features of both languages and let the PC do all the work with a minimum of code.

              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>

              Save the script with a .WSF extension and run from the command prompt:
              cscript scriptname.wsf

              By using the VBScript Now() function you can guarantee the JScript function receives the current local date and time. No need for The World Clock – Time Zone Converter.

              Currently the script echos the variable containing the UTC string to the console. One of the VBScript mavens on this board should be able to slice and dice the UTC string into an acceptable file label for the OP's zip file.

              Good luck. 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 #28 on: November 30, 2009, 07:38:55 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

              Salmon Trout

              • Guest
              Re: 2 part question about date in a batch file
              « Reply #29 on: November 30, 2009, 07:47:50 AM »
              If the user has registry read permission they can use vbs

              Code: [Select]
              od = now()
              set oShell = CreateObject("WScript.Shell")
              atb = "HKEY_LOCAL_MACHINE\System\CurrentControlSet\" &_
              "Control\TimeZoneInformation\ActiveTimeBias"
              offsetMin = oShell.RegRead(atb)
              StrUTC = dateadd("n", offsetMin, od)
              Wscript.Echo(StrUTC)