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

Author Topic: Help with script involving dates and days of week  (Read 12901 times)

0 Members and 1 Guest are viewing this topic.

Salmon Trout

  • Guest
Re: Help with script involving dates and days of week
« Reply #15 on: August 25, 2010, 03:27:43 PM »

usual rubbish


Why is he still here?

Fields



    Beginner

    Thanked: 3
    Help with script involving dates and days of week
    « Reply #16 on: August 25, 2010, 04:17:43 PM »

    I think we  got it!

    C:test>Display  mc.bat

    @echo off
    SET dwMONTH=%DATE:~4,2%
    echo dwMONTH=%dwMONTH%
    SET /A dwDAY=%DATE:~7,2%-16
    echo dwDAY=%dwDAY%
    SET dwYEAR=%DATE:~10,4%
    echo dwYEAR=%dwYEAR%
    if %dwday% LEQ 9 set dwday=0%dwday%
    SET  Datenow=%dwyear%%dwmonth%%dwday%

    QED

    __________________

    Post your complete code.

    Im not sure about your other two questions?

    When I back up against another month it fails also?

    Can this be fixed?  Also can the day of the week that corresponds to the date be returned as a variable?

    Day of week as a variable is already furnished:

    Datenow is a variable.

    « Last Edit: August 25, 2010, 04:37:31 PM by Fields »
    Member of the Human Race; Citizen of the World.

    ghostdog74



      Specialist

      Thanked: 27
      Re: Help with script involving dates and days of week
      « Reply #17 on: August 25, 2010, 05:39:09 PM »
      Many suggestions from the Ghost and Helpless about what does not work.

      But no suggestions or examples from the Ghost and Helpless of what can be done.

      The Cat Bell?
      better than giving wrong examples that cannot work, as you always did.
      My help is always the same regarding dates. Either use vbscript or totally forget about batch. Use a real programming language.

      Fields



        Beginner

        Thanked: 3
        Re: Help with script involving dates and days of week
        « Reply #18 on: August 25, 2010, 06:41:56 PM »

         When I back up against another month it fails also.


        The VBS/batch  works best for me.  Im still learning VBS.


        C:test>display  backday.bat

        @echo off
        CScript //nologo  backday.vbs  > back.txt

        set /p back=<back.txt
        set back=%back:~0,9%


        echo Back Date=%back%

        echo From Now -35 days

        Output:

        C:test> backday.bat
        Back Date=7/21/2010
        From Now -35 days

        C:test>Display   backday.vbs
        Wscript.Echo Now -35

        _________________________
        The Date Now is:
         Wed 08/25/2010

        « Last Edit: August 25, 2010, 06:59:18 PM by Fields »
        Member of the Human Race; Citizen of the World.

        Fields



          Beginner

          Thanked: 3
          Help with script involving dates and days of week
          « Reply #19 on: August 25, 2010, 09:01:32 PM »


           Also can the day of the week that corresponds to the date be returned as a variable?


          The following will find the day of the week for Now -35 days. The -35 should be a command line argument. But Im new to VBS and do not know how to pass an argument from the command line to the vbs script. I shall find the answer.

          C:test>display  day.bat

          @echo off
          rem Wscript.Echo WeekdayName(Weekday(Now -35))

          cscript //nologo  day.vbs  > weekday.txt

          set /p weekday=<weekday.txt

          set weekday=%weekday:~0,3%

          echo weekday=%weekday%

          echo when Now -35 days

          Output:

          C:test>day.bat
          weekday=Wed
          when Now -35 days

          C:test>
          Member of the Human Race; Citizen of the World.

          Dusty



            Egghead

          • I could if she would, but she won't so I don't.
          • Thanked: 75
          • Experience: Beginner
          • OS: Windows XP
          Re: Help with script involving dates and days of week
          « Reply #20 on: August 25, 2010, 11:37:27 PM »
          Perhaps this will help ???

          One good deed is worth more than a year of good intentions.

          Salmon Trout

          • Guest
          Re: Help with script involving dates and days of week
          « Reply #21 on: August 25, 2010, 11:52:31 PM »
          But Im new to VBS and do not know how to pass an argument from the command line to the vbs script. I shall find the answer.

          Study the numerous scripts you steal from other posters (mainly me).

          Fields



            Beginner

            Thanked: 3
            Help with script involving dates and days of week
            « Reply #22 on: August 26, 2010, 07:32:25 AM »
            Study the numerous scripts you steal from other posters (mainly me).


            The ST examples are the worst of all.  The attempt by ST  is to make VBS more complicated than it is.  The VBS functions do all the work, we simply supply needed arguments. There are many good examples on the internet.
            Member of the Human Race; Citizen of the World.

            Fields



              Beginner

              Thanked: 3
              Help with script involving dates and days of week
              « Reply #23 on: August 26, 2010, 12:01:37 PM »
              When I back up against another month it fails also.

              Also can the day of the week that corresponds to the date be returned as a variable?


              Find date last month and the weekday name with one script.


              C:test>display  dayback.bat

              @echo off
              rem backday.vbs
              rem Wscript.Echo Now -35
              CScript //nologo  backday.vbs  > back.txt
              set /p back=<back.txt
              set back=%back:~0,9%

              echo Back Date=%back%
              echo From Now -35 days

              rem Wscript.Echo WeekdayName(Weekday(Now -35))

              cscript //nologo  day.vbs  > weekday.txt

              set /p weekday=<weekday.txt

              set weekday=%weekday:~0,3%

              echo weekday=%weekday%

              echo when Now -35 days

              Output:

              C:test>dayback.bat
              Back Date=7/22/2010
              From Now -35 days
              weekday=Thu
              when Now -35 days

              C:test>
              Member of the Human Race; Citizen of the World.

              Salmon Trout

              • Guest
              Re: Help with script involving dates and days of week
              « Reply #24 on: August 26, 2010, 12:16:38 PM »
              I don't think anyone is reading this thread now, except for the masochists, and all your different login "names", Bill.

              Fields



                Beginner

                Thanked: 3
                Help with script involving dates and days of week
                « Reply #25 on: August 26, 2010, 02:11:10 PM »
                I dont think anyone is reading this thread now, except for the masochists, and all their different login names.


                This is excellent thread with excellent solutions.

                And all ST can say are his usual negative comments.



                Member of the Human Race; Citizen of the World.

                Salmon Trout

                • Guest
                Re: Help with script involving dates and days of week
                « Reply #26 on: August 26, 2010, 02:15:09 PM »

                And all ST can say is his usual negative comments.


                are his usual negative comments


                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: Help with script involving dates and days of week
                « Reply #27 on: August 26, 2010, 02:31:17 PM »
                Quote
                This is excellent thread with excellent solutions.

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

                Fields



                  Beginner

                  Thanked: 3
                  Help with script involving dates and days of week
                  « Reply #28 on: August 26, 2010, 05:18:22 PM »

                   When I back up against another month it fails also.

                   Also can the day of the week that corresponds to the date be returned as a variable?

                  The batch/vbs will accept any date (forward or back ) as a command line argument for the batch.
                  Echo and redirect (>) modifies the vbs files.  The command line argument must include + or -


                  C:test>Display  forbac.bat

                  @echo off

                  echo Wscript.Echo Now %1  > backday.vbs
                  CScript //nologo  backday.vbs  > back.txt
                  set /p back=<back.txt
                  set back=%back:~0,9%

                  echo Now%1=%back%
                  echo From Now %1 days

                  echo Wscript.Echo WeekdayName(Weekday(Now %1)) > day.vbs

                  cscript //nologo  day.vbs  > weekday.txt

                  set /p weekday=<weekday.txt

                  set weekday=%weekday:~0,3%

                  echo weekday%1=%weekday%

                  echo From Now %1 days

                  Output:

                  C:test> forbac.bat  +130
                  Now+130=1/3/2011
                  From Now +130 days
                  weekday+130=Mon
                  From Now +130 days

                  Output:

                  C:test> forbac.bat  -130
                  Now-130=4/18/2010
                  From Now -130 days
                  weekday-130=Sun
                  From Now -130 days

                  C:test>

                  ______________________________

                  It is now:
                  Thu 08/26/2010
                  « Last Edit: August 26, 2010, 05:54:56 PM by Fields »
                  Member of the Human Race; Citizen of the World.

                  Salmon Trout

                  • Guest
                  Re: Help with script involving dates and days of week
                  « Reply #29 on: August 27, 2010, 01:00:04 PM »
                                              ___________________________
                                     /|  /|  |                          |
                                     ||__||  |       Please don't       |
                                    /   O O\__           feed           |
                                   /          \       the troll         |
                                  /      \     \                        |
                                 /   _    \     \ ----------------------
                                /    |\____\     \     ||               
                               /     | | | |\____/     ||               
                              /       \|_|_|/   |    __||               
                             /  /  \            |____| ||               
                            /   |   | /|        |      --|               
                            |   |   |//         |____  --|               
                     * _    |  |_|_|_|          |     \-/               
                  *-- _--\ _ \     //           |                       
                    /  _     \\ _ //   |        /                       
                  *  /   \_ /- | -     |       |                         
                    *      ___ c_c_c_C/ \C_c_c_c____________