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

Author Topic: Convert date from MM/DD/YYYY into YYYYMMDD format  (Read 15856 times)

0 Members and 1 Guest are viewing this topic.

spshanth

    Topic Starter


    Greenhorn

    Convert date from MM/DD/YYYY into YYYYMMDD format
    « on: October 20, 2008, 12:12:04 AM »
    Hello all,

    My requirement is to get the date of a specific folder and to delete the same if the folder creation date is more than some 2 weeks.

    can any one help me in this.

    thanks in advance.

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: Convert date from MM/DD/YYYY into YYYYMMDD format
    « Reply #1 on: October 20, 2008, 05:59:14 AM »
    Batch code does not do date/time arithmetic very well. I have snippets in my closet going back to 1983, but not one of them does aging in batch code.

    How about a nice VBScript solution?

    Let us know.  8)
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    ALAN_BR



      Hopeful

      Thanked: 5
      • Computer: Specs
      • Experience: Experienced
      • OS: Windows 7
      Re: Convert date from MM/DD/YYYY into YYYYMMDD format
      « Reply #2 on: October 20, 2008, 07:11:26 AM »
      spshanth

      I wish you luck,
      but I fear you will get a lot more experience than you want !!!

      Created in 2003 I have C:\Windows.
      This is MUCH MORE than 2 weeks old.

      If I applied the rule of deleting a folder when it was two weeks old, it would save 4.7 GB of disc space, but I would not be able to do much with all that extra space but no operating system.

      The date of a folder does NOT indicate its most recent contents;
      it just possibly corresponds to the most recent file dates at the "root" of this folder,
      but ignores any more recent dates of folders and subsequent files it may contain.

      Whatever the rules (if any) may be, they probably depend upon whether you are looking at "Created" or "Modified".
      There are no rules for "Accessed".  If you use Windows Explorer to look in an obscure region you have not looked at for some time, you may see an ancient "Accessed" date.  This is meaningless.  If you reboot the computer you will now see it was accessed 5 minutes ago.  Accessed does not mean the contents were read or written.
      The "Accessed" date changes if Windows Explorer shows that file exists,
      but it will NOT change if you use the "DOS" command "DIR".

      File dates are interesting, and quite useful, but I would not depend upon them to control what gets deleted.

      Regards
      Alan

      spshanth

        Topic Starter


        Greenhorn

        Re: Convert date from MM/DD/YYYY into YYYYMMDD format
        « Reply #3 on: October 21, 2008, 06:43:09 AM »
        thanks for the response.

        But i have to do this in a DOS batch script only and cannot use VBS here :(

        is there any other way to handle this situation oter than using the date manipualtion logic??

        Thnaks.

        Sidewinder



          Guru

          Thanked: 139
        • Experience: Familiar
        • OS: Windows 10
        Re: Convert date from MM/DD/YYYY into YYYYMMDD format
        « Reply #4 on: October 21, 2008, 04:29:17 PM »
        Quote
        Convert date from MM/DD/YYYY into YYYYMMDD format

        Code: [Select]
        @echo off
        set dt=mm/dd/yyyy
        set newdate=%dt:~6,4%%dt:~0,2%%dt:~3,2%
        echo %newdate%

        It becomes problematical when using arithmetic on dates. Everything is fine if both dates are in the same month. The real fun begins when you "borrow" days from the previous month.

         8)

        I can't sell a VBS script to anyone today. :(
        The true sign of intelligence is not knowledge but imagination.

        -- Albert Einstein

        spshanth

          Topic Starter


          Greenhorn

          Re: Convert date from MM/DD/YYYY into YYYYMMDD format
          « Reply #5 on: October 21, 2008, 11:34:40 PM »
          thanks sidewinder... :)