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

Author Topic: time  (Read 19198 times)

0 Members and 1 Guest are viewing this topic.

Helpmeh



    Guru

  • Roar.
  • Thanked: 123
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 8
Re: time
« Reply #15 on: March 31, 2010, 07:13:31 PM »
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>
End time=20:0:31.87?
Where's MagicSpeed?
Quote from: 'matt'
He's playing a game called IRL. Great graphics, *censored* gameplay.

ghostdog74



    Specialist

    Thanked: 27
    Re: time
    « Reply #16 on: March 31, 2010, 07:35:08 PM »
    Code: [Select]
    C:\batch> add2.bat
    start time=20:07:14.17
    Hour=20
    minutes=07
    minutes plus 1=8
    C:\batch>

    how about hours? after 24 comes 00.

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: time
    « Reply #17 on: March 31, 2010, 07:47:04 PM »
    how about hours? after 24 comes 00.
    No. There is no 24.
    The clock goes from 00:00  to 23:59
    But in 12 hour notation it goes from
    12:00 AM to 11:59 PM
    Ane then from
    12:00 PM to 11:59 PM

    ghostdog74



      Specialist

      Thanked: 27
      Re: time
      « Reply #18 on: March 31, 2010, 07:52:22 PM »
      hah, yes you are right. its 23:59

      greg



        Intermediate

        Thanked: 7
        Re: time
        « Reply #19 on: March 31, 2010, 08:28:03 PM »
        How about hours? after 24 comes 00.

        Output:

        C:\batch>add3.bat
        start time=23:59:20.59
        Hour=23
        MM1=0
        HH=0

        C:\batch>type add3.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%
        If  %HH%==23 goto end
        set /a HH=%HH% + 1
        echo minutes plus 1=%MM1%
        echo Hour=%HH%
        :end
        If %HH%==23 set /a HH=0
        echo HH=%HH%
        Have a Nice Day

        ghostdog74



          Specialist

          Thanked: 27
          Re: time
          « Reply #20 on: March 31, 2010, 08:33:43 PM »
          using your new code and setting TIME variable to 23:58.59.00 gives me
          Code: [Select]
          C:\test>test.bat
          start time=23:58:59.00
          Hour=23
          minutes=58
          minutes plus 1=59
          HH=0
          if HH is the final answer for hours, then 0 in the above result is incorrect.

          greg



            Intermediate

            Thanked: 7
            Re: time
            « Reply #21 on: March 31, 2010, 08:40:36 PM »
            How can I add one minute to the current time and store it as a variable

            The batch solution is the best solution. Matt123 ask for the minutes plus
            one minute be assigned to a "Dos" variable.  This has been accomplished.

            The 59 minute bug and the 23 Hour bug has been corrected.

            I will not write any code for a 12 hour clock.

            QED

            p.s.  "Sometime we cannot see the forest; we can only see the trees."
            Have a Nice Day

            ghostdog74



              Specialist

              Thanked: 27
              Re: time
              « Reply #22 on: March 31, 2010, 08:54:43 PM »
              The batch solution is the best solution.
              yeah right. in a million years

              Quote
              Matt123 ask for the minutes plus
              one minute be assigned to a "Dos" variable.  This has been accomplished.
              no, it has not. you won't know what time format his PC is  beforehand, so you have to take care of that.

              greg



                Intermediate

                Thanked: 7
                Re: time
                « Reply #23 on: March 31, 2010, 09:02:14 PM »
                using your new code and setting TIME variable to 23:58.59.00 gives me
                if HH is the final answer for hours, then 0 in the above result is incorrect.

                Thanks for finding the minor bugs.  Code written here in few minutes is not
                production code. We are not being paid.

                p.s. Ghostdog74,  I have not seen any output of the code you wrote for this thread.

                I believe the Batch code is the best solution. Matt, the Original Poster, requested a batch solution. I have not  seen Ghostdog74's batch solution.

                Have a Nice Day

                Helpmeh



                  Guru

                • Roar.
                • Thanked: 123
                  • Yes
                  • Yes
                • Computer: Specs
                • Experience: Familiar
                • OS: Windows 8
                Re: time
                « Reply #24 on: March 31, 2010, 09:10:54 PM »
                Greg, I hate to take the wind out of your sails, but batch is terrible at date manipulation. VBS isn't the BEST, but it is better than what pure batch can do.
                Where's MagicSpeed?
                Quote from: 'matt'
                He's playing a game called IRL. Great graphics, *censored* gameplay.

                Geek-9pm


                  Mastermind
                • Geek After Dark
                • Thanked: 1026
                  • Gekk9pm bnlog
                • Certifications: List
                • Computer: Specs
                • Experience: Expert
                • OS: Windows 10
                Re: time
                « Reply #25 on: March 31, 2010, 09:21:37 PM »
                This is a lot of FUN!

                Is anybody taking this seriously?   8)

                Professional administrators have done this sort of thing years ago. You can manipulate the date in batch scripts without the need to use VBscript or something like that. The trick is to understand the conversion to Julian date. The DOS DATE command does not do Julian date number, but you can convert it and do some add or subtract and come up with an answer. But you need to define what a 'month' is. Often when people say 'in a month', they mean exactly 30 days.

                Here is how you do Julian date in DOS. Read it if you dare.
                http://www.robvanderwoude.com/datetimentmath.php

                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 #26 on: April 01, 2010, 04:34:12 AM »

                Professional administrators have done this sort of thing years ago. You can manipulate the date in batch scripts without the need to use VBscript or something like that. The trick is to understand the conversion to Julian date. The DOS DATE command does not do Julian date number, but you can convert it and do some add or subtract and come up with an answer.
                So you need to convert to a julian date, do the addition, and then convert back. just leverage both batch and VBScript at once.


                C:\Users\BC_Programming>for /f "tokens=*" %P in ('cscript /NOLOGO temp.vbs') do
                set newdate=%P
                Code: [Select]
                @echo off
                echo WScript.echo(time+(1/24/60)) >> temp.vbs&&for /f "tokens=*" %%P in ('Cscript /NOLOGO temp.vbs') do set newdate=%%P
                del temp.vbs

                after running this, the newdate variable will have the current  time plus a minute. Note there isn't a huge advantage between this solution and gregs; the only difference is this one can easily be told to use the entire date by changing time to now, whereas the pure batch solution will then need to have a lot of checks for overflows to the next date,month, and year.

                Quote
                But you need to define what a 'month' is. Often when people say 'in a month', they mean exactly 30 days.
                Er... No. They almost always mean the same date in the following month. Depends on the context, though.

                For example, if it's the 12th, and somebody says, "in a month" they might mean the 12th of the following month, or they might mean 30.

                I  think the most important thing here is that we are adding minutes, so it really won't matter how long a month is; it might if we were considering a complete Date/Time,  but the OP only said the current time... so we go with that.


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

                Sidewinder



                  Guru

                  Thanked: 139
                • Experience: Familiar
                • OS: Windows 10
                Re: time
                « Reply #27 on: April 01, 2010, 07:19:22 AM »
                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>

                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

                No need for a script file. You can run from the command prompt:

                mshta vbscript:(MsgBox(DateAdd("n",1,Now)))

                No. There is no 24.
                The clock goes from 00:00  to 23:59
                But in 12 hour notation it goes from
                12:00 AM to 11:59 PM
                Ane then from
                12:00 PM to 11:59 PM

                In the US military there is a twenty-four hundred hours, however the first tick past midnight becomes zero hundred hours.

                Just thought I'd throw that in.  8)
                The true sign of intelligence is not knowledge but imagination.

                -- Albert Einstein

                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 #28 on: April 01, 2010, 07:43:03 AM »
                Quote
                No need for a script file. You can run from the command prompt:

                Except that using that method there is no way to get the output directly back into a environment variable.
                I was trying to dereference Null Pointers before it was cool.

                ghostdog74



                  Specialist

                  Thanked: 27
                  Re: time
                  « Reply #29 on: April 01, 2010, 07:46:51 AM »
                  mshta vbscript:(MsgBox(DateAdd("n",1,Now)))
                  for this example maybe. but if its part of a larger program, then maybe not. a script/file is still needed.