Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Formatting Modified Date Variable in Batch File

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 21-10-2011
Member
 
Join Date: Oct 2011
Posts: 1
Formatting Modified Date Variable in Batch File
  

I'm creating a batch file that loops through files in my directory, executes a program and renames files based on modified date. I am able to set 'mydate'= to the modified date, but in order to append that date to the file name I need to format it mmddyyyy.

How do I format 'mydate' to mmddyyy? It currently reads mm/dd/yyyy hh:mm AM(PM)
Code:
ChDIR C:\Users\finanalyst1433\Desktop\New folder\Output\
SETLOCAL enabledelayedexpansion
FOR %%f IN (*.o_g) DO (
	CALL C:\RTSimEXE\RTOutput.exe %cd%\%%f Month
	set mydate=%%~Tf	)
FOR %%f IN (*_Mon.csv) DO REN "%%f" "%%~nf_%mydate%%%~xf
SET deletestring=_Mon
FOR /f "delims==" %%F IN ('dir /b *.csv ^| FIND "%deletestring%"') DO (
	SET oldfilename=%%F
	SET newfilename=!oldfilename:%deletestring%=!
	REN "!oldfilename!" "!newfilename!"
	)
EXIT

Reply With Quote
  #2  
Old 21-10-2011
Member
 
Join Date: May 2008
Posts: 3,514
Re: Formatting Modified Date Variable in Batch File

Check the Windows Batch File (.bat) to get current date in MMDDYYYY format.:
Code:
@echo off
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
For /f "tokens=1-2 delims=/:" %%a in ('time /t') do (set mytime=%%a%%b)
echo %mydate%_%mytime%
If you prefer the time in 24hr/military format, you can replace the second FOR line with this:
Code:
For /f "tokens=1-2 delims=/:" %%a in ("%TIME%") do (set mytime=%%a%%b)
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Formatting Modified Date Variable in Batch File"
Thread Thread Starter Forum Replies Last Post
Windows 7 resetting modified date on Files automatically while moving Dvimida Operating Systems 3 12-01-2012 08:48 AM
Windows batch file: set output of program to a variable? supernoob Windows Software 5 17-10-2010 06:58 AM
How do i modified pst file in Outlook Atilla Windows Software 4 30-04-2009 11:53 AM
Date and Time format in a BATCH File RogerFielden Software Development 3 20-04-2009 12:47 PM
Batch file to create directory with a date in Windows 2003 Aadimoolan Window 2000 Help 2 16-11-2007 02:55 AM


All times are GMT +5.5. The time now is 05:41 PM.