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

Author Topic: Batch file: getting only the last 2 digits of the year  (Read 24354 times)

0 Members and 1 Guest are viewing this topic.

BatchRocks



    Hopeful
  • Thanked: 3
    Re: Batch file: getting only the last 2 digits of the year
    « Reply #15 on: March 12, 2009, 04:59:43 AM »
    You amaze me.

    It's 09, Echo 09, In 2010, Echo 10

    Dias de verano

    • Guest
    Re: Batch file: getting only the last 2 digits of the year
    « Reply #16 on: March 12, 2009, 05:05:58 AM »
    I really really hate debug scripts. Cryptic plus they create .com executables of unprovable (to most users) freedom from nasty side effects. You can do all the date stuff in VBScript, and writing a batch to supply parameters and get back data is a trivial task, and the workings are (reasonably) transparent.

    macdad-



      Expert

      Thanked: 40
      Re: Batch file: getting only the last 2 digits of the year
      « Reply #17 on: March 12, 2009, 06:14:22 AM »
      You amaze me.

      It's 09, Echo 09, In 2010, Echo 10

      who?

      but heck Reno, just basically owned it..but why create an executable?
      If you dont know DOS, you dont know Windows...

      Thats why Bill Gates created the Windows NT Family.

      BatchFileCommand



        Hopeful
      • Thanked: 1
        Re: Batch file: getting only the last 2 digits of the year
        « Reply #18 on: March 12, 2009, 06:17:11 AM »
        I think this thread is pointless! WHO CARES ABOUT THE LAST DIGITS OF THE YEAR! just do this.

        Code: [Select]
        echo %date:-~4%

        I don't think you will need this program in 7991 years (when they add another digit to the date).
        οτη άβγαλτος μεταφ βαθμολογία

        macdad-



          Expert

          Thanked: 40
          Re: Batch file: getting only the last 2 digits of the year
          « Reply #19 on: March 12, 2009, 06:19:01 AM »
          if he wants the last two digits, then so be it.

          but i think we scared away ADH....whoops
          If you dont know DOS, you dont know Windows...

          Thats why Bill Gates created the Windows NT Family.

          Reno



            Hopeful
          • Thanked: 32
            Re: Batch file: getting only the last 2 digits of the year
            « Reply #20 on: March 12, 2009, 06:26:23 AM »
            my preference in batch is to stick with the availaible command on working environment. but sometimes using batch cmd only has its limitation, namely accessing RTC, date manipulation, floating point math, program automation, accessing http, etc.
            i am not doubting that VBScript can do a lot of stuff in a few lines, i often use it too when i got stuck with just cmd.
            as for malicious code, i believe there is more of it written in vbs rather than ms-debug.

            maybe the debug code could be useful in DOS. it's just an example on various ways to get YY of date. i will delete that part if anyone is offended with the code. just let me know.
            i edited the code to include warning message before creating the .com executable file.

            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: Batch file: getting only the last 2 digits of the year
            « Reply #21 on: March 12, 2009, 07:52:01 AM »
            Code: [Select]
            echo wscript.echo right(year(CDate(wscript.arguments(0))),2) > temp.vbs
            start temp.vbs

            it will echo the last two digits of the year. Note that the provided date will need to be in a format recognized by the current system locale; mine for example is mm/dd/yyyy. Also, it crashes if no arguments are provided with subscript out of range (not surprising).

            I cant remember the for command used to redirect output of a command into a environment variable, but I'm sure that would work here.

            @Reno: I don't think anybody really had an issue with the debug script, just that it's a bit much  :P

            Also- you can open a VBScript and read it- that isn't possible with an assembled COM file.

            And another problem is that Debug, I believe creates a Tiny Memory model 16-bit Dos executable, which won't run on a 64-bit machine  :(

            of course as a solution for pure DOS which doesn't have VBScript installed, (and also assuming it's a MS-DOS distribution as opposed to PC-DOS which included REXX) then it's a workable solution.

            I think this thread is pointless! WHO CARES ABOUT THE LAST DIGITS OF THE YEAR! just do this.

            Code: [Select]
            echo %date:-~4%

            I don't think you will need this program in 7991 years (when they add another digit to the date).

             ::)

            Not exactly portable to different locales. my %DATE% variable is:
            Code: [Select]
            Thu 03/12/2009
            hmm, start at the fourth character...
            Code: [Select]
            03/12/2009
            and we get the entire date; so I'm confused as to what this accomplishes.

            Also, I might add it doesn't even do that, it just echos "date:-~4".

            Not sure exactly how that would work anyway, since even if the format was, for example yyyy/mm/dd, then it would just grab the entire date, not counting the weekday.


            I was trying to dereference Null Pointers before it was cool.

            macdad-



              Expert

              Thanked: 40
              Re: Batch file: getting only the last 2 digits of the year
              « Reply #22 on: March 12, 2009, 11:14:43 AM »
              Code: [Select]
              echo wscript.echo right(year(CDate(wscript.arguments(0))),2) > temp.vbs
              start temp.vbs

              it will echo the last two digits of the year. Note that the provided date will need to be in a format recognized by the current system locale; mine for example is mm/dd/yyyy. Also, it crashes if no arguments are provided with subscript out of range (not surprising).

              I cant remember the for command used to redirect output of a command into a environment variable, but I'm sure that would work here.

              @Reno: I don't think anybody really had an issue with the debug script, just that it's a bit much  :P

              Also- you can open a VBScript and read it- that isn't possible with an assembled COM file.

              And another problem is that Debug, I believe creates a Tiny Memory model 16-bit Dos executable, which won't run on a 64-bit machine  :(

              of course as a solution for pure DOS which doesn't have VBScript installed, (and also assuming it's a MS-DOS distribution as opposed to PC-DOS which included REXX) then it's a workable solution.

               ::)

              Not exactly portable to different locales. my %DATE% variable is:
              Code: [Select]
              Thu 03/12/2009
              hmm, start at the fourth character...
              Code: [Select]
              03/12/2009
              and we get the entire date; so I'm confused as to what this accomplishes.

              Also, I might add it doesn't even do that, it just echos "date:-~4".

              Not sure exactly how that would work anyway, since even if the format was, for example yyyy/mm/dd, then it would just grab the entire date, not counting the weekday.

              you actually dont need all that code:

              Code: [Select]
              @echo off
              set digit=%DATE:~12,2%
              echo %digit%
              pause

              but if you have a different date format, then let me know(this one is DDD MM/DD/YYYY, e.g. Thu 03/11/2009)

              Hope this Helps
              ,Nick(macdad-)

               ::)
              it doesn't need VBScript, nor Debug....

              If you dont know DOS, you dont know Windows...

              Thats why Bill Gates created the Windows NT Family.

              Dias de verano

              • Guest
              Re: Batch file: getting only the last 2 digits of the year
              « Reply #23 on: March 12, 2009, 11:24:31 AM »
              Code: [Select]
              @echo off
              set digit=%DATE:~12,2%
              echo %digit%
              pause

              Macdad, what exactly is that code supposed to do?

              macdad-



                Expert

                Thanked: 40
                Re: Batch file: getting only the last 2 digits of the year
                « Reply #24 on: March 12, 2009, 11:26:32 AM »
                retrieve the last two digits of the year...and i already asked if he need another one if he had his regional settings different:
                http://www.computerhope.com/forum/index.php/topic,78577.msg517776.html#msg517776

                thats what ADH wanted:
                Like in: for /f "tokens=1-4 delims=/ " %%d in ("%date%") do @echo %%f%%e%%d
                but I want only the 09 out of 2009
                If you dont know DOS, you dont know Windows...

                Thats why Bill Gates created the Windows NT Family.

                Dias de verano

                • Guest
                Re: Batch file: getting only the last 2 digits of the year
                « Reply #25 on: March 12, 2009, 11:32:46 AM »
                i already asked if he need another one if he had his regional settings different:

                ADH never answered.

                macdad-



                  Expert

                  Thanked: 40
                  Re: Batch file: getting only the last 2 digits of the year
                  « Reply #26 on: March 12, 2009, 11:33:16 AM »
                  i know:

                  if he wants the last two digits, then so be it.

                  but i think we scared away ADH....whoops
                  If you dont know DOS, you dont know Windows...

                  Thats why Bill Gates created the Windows NT Family.