Results 1 to 4 of 4

Thread: Date and Time format in a BATCH File

  1. #1
    Join Date
    Apr 2009
    Posts
    55

    Date and Time format in a BATCH File

    Hello,

    Can we set the Date and Time for certain Batch files even though that Batch files need not to be forwarded but want to show that batch files should be updated for each time.when we login to the system.

    This processing would keep backup of all the files and folders that we have selected for Batch Processing.

    Thanks

  2. #2
    Join Date
    Jan 2009
    Posts
    99

    Re: Date and Time format in a BATCH File

    IDATE.BAT:
    This batch file checks the date format setting (mm/dd/yy, dd/mm/yy or yy/mm/dd):

    @ECHO OFF
    :: For REG.EXE 3.0 (Windows XP) and later versions
    FOR /F "tokens=3" %%A IN ('REG QUERY "HKEY_CURRENT_USER\Control Panel\International" /v iDate 2ˆ>NUL') DO SET iDate=%%A
    :: For earlier REG.EXE versions
    FOR /F "tokens=3" %%A IN ('REG QUERY "HKEY_CURRENT_USER\Control Panel\International\iDate" 2ˆ>NUL') DO SET iDate=%%A
    ECHO HKEY_CURRENT_USER\Control Panel\International\iDate=%iDate%

  3. #3
    Join Date
    Mar 2008
    Posts
    258

    Re: Date and Time format in a BATCH File

    Just copy and paste the text in quotes to a text file. Then rename file test.bat and run from command line to see (echo is on by default).

    This can be used in a very powerful way, the FOR command can be reused and changed to query to see if a file exists and then if so create the folder, etc.

    for now, lets start basic…

    Code:
    echo on
          @REM Seamonkey’s quick date batch (MMDDYYYY format)
          @REM Setups %date variable
          @REM First parses month, day, and year into mm , dd, yyyy formats and then combines to be MMDDYYYY
    
          FOR /F “TOKENS=1* DELIMS= ” %%A IN (’DATE/T’) DO SET CDATE=%%B
          FOR /F “TOKENS=1,2 eol=/ DELIMS=/ ” %%A IN (’DATE/T’) DO SET mm=%%B
          FOR /F “TOKENS=1,2 DELIMS=/ eol=/” %%A IN (’echo %CDATE%’) DO SET dd=%%B
          FOR /F “TOKENS=2,3 DELIMS=/ ” %%A IN (’echo %CDATE%’) DO SET yyyy=%%B
          SET date=%mm%%dd%%yyyy%
    this does nothing but setup the %date variable to be todays date in MMDDYYYY format so it can be called later in the script, etc..

  4. #4
    Join Date
    Oct 2008
    Posts
    167

    Re: Date and Time format in a BATCH File

    The only way I know that I know that what you are trying to do might be possible is using the for command and the ~t expanding parameter.

    for %r in (*.*) DO echo %r "created on" %~tr
    That produces:
    C:\>echo BOOTSECT.BAK "created on" 2009/02/17 11:59 PM
    BOOTSECT.BAK "created on" 2009/02/17 11:59 PM

    C:\>echo config.sys "created on" 2006/09/18 11:43 PM
    config.sys "created on" 2006/09/18 11:43 PM
    I think a more likely scenario would involve using windows scripting host, or powershell, but you did not mention that those are options for you, so I am assuming that there is a good reason, for not being able to use those technologies.

Similar Threads

  1. Formatting Modified Date Variable in Batch File
    By erock24 in forum Software Development
    Replies: 1
    Last Post: 21-10-2011, 12:39 PM
  2. How to run batch file at specific time
    By Campbel in forum Software Development
    Replies: 4
    Last Post: 27-03-2010, 07:32 PM
  3. Format Date and Time Script in ASP
    By Beter 2 Burn Out in forum Software Development
    Replies: 4
    Last Post: 10-02-2010, 02:22 AM
  4. Batch file to create directory with a date in Windows 2003
    By Aadimoolan in forum Window 2000 Help
    Replies: 2
    Last Post: 16-11-2007, 02:55 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,287,308.81765 seconds with 17 queries