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

Author Topic: directory name=date and hour?  (Read 2049 times)

0 Members and 1 Guest are viewing this topic.

mumin

    Topic Starter


    Newbie

    directory name=date and hour?
    « on: January 31, 2009, 08:22:52 PM »
    Hi

    Newbie, its late and I'm tired. Need help.
    In a batch file: I wanna make a directory with the name = "date and hour" (yyyy-mm-dd-hour). For example:

    2009-02-01-04

    Don't know how to get the hour in a variable (with the date).

    In xp pro.

    BatchRocks



      Hopeful
    • Thanked: 3
      Re: directory name=date and hour?
      « Reply #1 on: January 31, 2009, 08:35:03 PM »
      Hmm...

      This spits out the date and time:


      Code: [Select]
      @echo off
      time /t >> T.txt
      date /t >> T.txt
      exit

      It makes it into a new file, named T.txt.

      Dusty



        Egghead

      • I could if she would, but she won't so I don't.
      • Thanked: 75
      • Experience: Beginner
      • OS: Windows XP
      Re: directory name=date and hour?
      « Reply #2 on: February 01, 2009, 12:34:31 AM »
      Mumin - Welcome to the CH forums.

      Try this:
      Code: [Select]

      @echo off
      cls
      set datime=%date%-%time:~0,2%

      echo %datime%

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

      GuruGary



        Adviser
        Re: directory name=date and hour?
        « Reply #3 on: February 01, 2009, 12:49:01 AM »
        Manipulating the date and time environment variables is dependent on your Windows regional settings ... but for the U.S. English default settings for Windows XP, you can use:
        Code: [Select]
        md "%date:~-4%-%date:~-10,2%-%date:~-7,2%-%time:~0,2%"
        And I guess you would want to substitute the space with a 0 (when the hour is less than 10) like:
        Code: [Select]
        set DateHr=%date:~-4%-%date:~-10,2%-%date:~-7,2%-%time:~0,2%
        md "%DateHr: =0%"

        mumin

          Topic Starter


          Newbie

          Re: directory name=date and hour?
          « Reply #4 on: February 01, 2009, 07:00:44 AM »
          Thanks all, that did the trick. Nice response. It's a batch file to make sorting and stuff easier/quicker managing photos from my camera.