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

Author Topic: time  (Read 19202 times)

0 Members and 1 Guest are viewing this topic.

mat123

    Topic Starter


    Hopeful

    Thanked: 16
    • Yes
    • Yes
    • Yes
  • Experience: Familiar
  • OS: Windows XP
time
« on: March 31, 2010, 12:12:10 AM »
how can i add one minute to the current time and store it as a variable



T.C.



    Beginner

    Thanked: 13
    Re: time
    « Reply #1 on: March 31, 2010, 01:12:47 AM »
    Start by advising the format of your system time as returned when time/t is entered.

    ghostdog74



      Specialist

      Thanked: 27
      Re: time
      « Reply #2 on: March 31, 2010, 03:24:21 AM »
      again this topic, batch is never good dealing with time/date. Use vbscript

      Code: [Select]
      WScript.Echo DateAdd("n",1,Now)
      or a good programming language eg Python

      Code: [Select]
      >>> import time,datetime
      >>> t = datetime.datetime.now()
      >>> t.ctime()
      'Wed Mar 31 16:30:24 2010'
      >>> back=datetime.datetime.fromtimestamp(time.mktime(t.timetuple())+60)
      >>> back.ctime()
      'Wed Mar 31 16:31:24 2010'


      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: time
      « Reply #3 on: March 31, 2010, 06:44:22 AM »
      yes. as you can see python is clearly the winner here since it's four lines instead of 1.

      Anyway for some reason I hardly ever use the DateAdd() function. Usually I just add the direct number equivalent (each whole numer is a day, an hour is 1/24, a minute is 1/24/60, etc. This is solely because I'm crazy. (Although I like to blame the fact that DateDiff was so filled with bugs for so many years and I just sort of grouped them all in the same department)
      I was trying to dereference Null Pointers before it was cool.

      ghostdog74



        Specialist

        Thanked: 27
        Re: time
        « Reply #4 on: March 31, 2010, 06:54:38 AM »
        yes. as you can see python is clearly the winner here since it's four lines instead of 1.
        lol. sarcasm? anyway, the datetime module in Python has much more features than what vbscript Date functions provides. when you see it this way, clearly Python is the winner. :)

        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: time
        « Reply #5 on: March 31, 2010, 07:08:37 AM »
        lol. sarcasm? anyway, the datetime module in Python has much more features than what vbscript Date functions provides, if you would like to know.


        And they probably weren't broken for 5+ years, either.

        (that's totally frank, not sarcastic, btw)

        There is probably a faster way to do it in python, also. In fact, everything you have there could be combined (I think, just want to exercise python here):
        Code: [Select]
        datetime.datetime.fromtimestamp(time.mktime(datetime.datetime.now().timetuple())+60).ctime()

        Seems a tad verbose. Oh well.

        Actually, VBScript is miles ahead of Batch but at the same time it's date support really blows, solely because it's all handled in OLEAUT32. Now, it works for your everyday date and time calculations but it leaves out important and useful things like converting between time zones and or calculating UTC times, something that from a quick look at the documentation it appears that python probably does.

        That being said the date and time support in the .NET framework is "fixed" and actually works properly with UTC dates and time zone information. It's a very rich framework much like the modules included with Python. For example, in powershell, the following would display the current time plus one minute.

        Code: [Select]
        [System.DateTime]::Now.AddMinutes(1)



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

        ghostdog74



          Specialist

          Thanked: 27
          Re: time
          « Reply #6 on: March 31, 2010, 07:36:12 AM »
          There is probably a faster way to do it in python, also. In fact, everything you have there could be combined (I think, just want to exercise python here):
          sure, that's the beauty of objects. I prefer to break it down to intermediate steps for readability though

          Quote
          Actually, VBScript is miles ahead of Batch but at the same time it's date support really blows, solely because it's all handled in OLEAUT32. Now, it works for your everyday date and time calculations but it leaves out important and useful things like converting between time zones and or calculating UTC times, something that from a quick look at the documentation it appears that python probably does.
          precisely. not just Python, Perl as well has very good featured datetime libraries for advance date ops

          Quote
          That being said the date and time support in the .NET framework is "fixed" and actually works properly with UTC dates and time zone information. It's a very rich framework much like the modules included with Python. For example, in powershell, the following would display the current time plus one minute.
          i agree. powershell is probably the way to go for modern windows scripting.

          mat123

            Topic Starter


            Hopeful

            Thanked: 16
            • Yes
            • Yes
            • Yes
          • Experience: Familiar
          • OS: Windows XP
          Re: time
          « Reply #7 on: March 31, 2010, 08:57:57 AM »
          can any of the codes store the new time in dos.



          greg



            Intermediate

            Thanked: 7
            Re: time
            « Reply #8 on: March 31, 2010, 04:28:17 PM »
            Can any of the codes store the new time in batch.

            Yes the following batch code assigns minute plus 1 to variable MM1:


            C:\batch>type   addminute.bat
            Code: [Select]
            @echo OFF

            REM time format 12:46:26.94

            echo start time=%TIME%

            set HH=%TIME:~0,2%

            echo Hour=%HH%

            set MM=%TIME:~3,2%

            echo minutes=%MM%

            set /a MM1=%MM% + 1

            echo minutes plus 1=%MM1%

            Output:

            C:\batch> addminute.bat
            start time=17:27:13.98
            Hour=17
            minutes=27
            minutes plus 1=28
            C:\batch>
            Have a Nice Day

            Sidewinder



              Guru

              Thanked: 139
            • Experience: Familiar
            • OS: Windows 10
            Re: time
            « Reply #9 on: March 31, 2010, 06:02:56 PM »
            Not to be too obvious, but I think you need a plan B:

            Quote
            C:\batch> addminute.bat
            start time=17:27:13.98
            Hour=17
            minutes=27
            minutes plus 1=28
            C:\batch>

            What happens if the minutes value is 59?

            Just asking.  8)
            The true sign of intelligence is not knowledge but imagination.

            -- Albert Einstein

            Helpmeh



              Guru

            • Roar.
            • Thanked: 123
              • Yes
              • Yes
            • Computer: Specs
            • Experience: Familiar
            • OS: Windows 8
            Re: time
            « Reply #10 on: March 31, 2010, 06:16:18 PM »
            Not to be too obvious, but I think you need a plan B:

            What happens if the minutes value is 59?

            Just asking.  8)
            Quote
            C:\batch> addminute.bat
            start time=19:59:35.10
            Hour=18
            minutes=59
            minutes plus 1=60
            C:\batch>
            Where's MagicSpeed?
            Quote from: 'matt'
            He's playing a game called IRL. Great graphics, *censored* gameplay.

            ghostdog74



              Specialist

              Thanked: 27
              Re: time
              « Reply #11 on: March 31, 2010, 06:23:23 PM »
              Yes the following batch code assigns minute plus 1 to variable MM1:
              you cannot just add your minute like that. after 59, it should be 00, not 60 and then the hour incremented. you will need a more elaborate method.

              Geek-9pm


                Mastermind
              • Geek After Dark
              • Thanked: 1026
                • Gekk9pm bnlog
              • Certifications: List
              • Computer: Specs
              • Experience: Expert
              • OS: Windows 10
              Re: time
              « Reply #12 on: March 31, 2010, 06:24:13 PM »
              Quote
              Microsoft Windows XP [Version 5.1.2600]
              (C) Copyright 1985-2001 Microsoft Corp.

              d:\batch>WScript.Echo DateAdd("n",1,Now)
              'WScript.Echo' is not recognized as an internal or external command,
              operable program or batch file.

              d:\batch>

              Did I miss something?

              EDIT:
              IF minutes =59   ????
              IF hours = 23  ????
              IF days = 28 and month = February ??
              IF mod(year/4) = 0  ???
              IF you are on a ship and...
              about to cross the international date line in 30 seconds
                 ::) ::)

              ghostdog74



                Specialist

                Thanked: 27
                Re: time
                « Reply #13 on: March 31, 2010, 06:31:03 PM »
                Did I miss something?
                yes. that's a vbscript statement. so you cannot run it like that. you put that in a file and then run it using cscript.exe
                Code: [Select]
                cscript //nologo mydateadd.vbs

                greg



                  Intermediate

                  Thanked: 7
                  Re: time
                  « Reply #14 on: March 31, 2010, 07:09:58 PM »
                  Not to be too obvious, but I think you need a plan B:

                  What happens if the minutes value is 59?


                  C:\batch>type  addplanB.bat

                  Code: [Select]
                  @echo OFF

                  REM time format 12:46:26.94

                  echo start time=%TIME%

                  set HH=%TIME:~0,2%

                  echo Hour=%HH%

                  set MM=%TIME:~3,2%
                  if %MM%==59 Goto  adjust



                  echo minutes=%MM%

                  set /a MM1=%MM% + 1

                  echo minutes plus 1=%MM1%

                  if %MM1%==60 goto adjust
                  goto end
                  :adjust
                  set /a MM1=0
                  echo MM1=%MM1%
                  Pause
                  set /a HH=%HH% + 1
                  echo minutes plus 1=%MM1%
                  echo Hour=%HH%
                  :end
                  Output:

                  C:\batch> add2.bat
                  start time=19:59:31.87
                  Hour=19
                  MM1=0
                  Press any key to continue . . .
                  minutes plus 1=0
                  Hour=20

                  C:\batch>


                  C:\batch> add2.bat
                  start time=20:07:14.17
                  Hour=20
                  minutes=07
                  minutes plus 1=8
                  C:\batch>
                  Have a Nice Day