7 Replies - 3261 Views - Last Post: 24 November 2011 - 03:51 AM Rate Topic: -----

#1 naveed_786  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 306
  • Joined: 13-October 09

SET Date in Batch File

Posted 19 November 2011 - 04:05 AM

Dear All,

How can i set date in batch file

for /f "tokens=2,3,4 delims=://>" %%i in ("%DATE%")  do set DATE=%%i.%%j.%%k
md "c:\TEST\TTT\%DATE%"



This peace of code makes folder 19.2011 but i want 19.11.2011 or 11.19.2011

How to achieve this please help me.

This post has been edited by naveed_786: 19 November 2011 - 04:10 AM

Is This A Good Question/Topic? 0
  • +

Replies To: SET Date in Batch File

#2 calvinthedestroyer  Icon User is offline

  • D.I.C Lover

Reputation: 167
  • View blog
  • Posts: 1,908
  • Joined: 13-October 07

Re: SET Date in Batch File

Posted 20 November 2011 - 05:37 PM

I think you need a third variable for storing your formatted date.
Since DATE is a system variable you can't changed it.
Was This Post Helpful? 0
  • +
  • -

#3 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,277
  • Joined: 28-March 11

Re: SET Date in Batch File

Posted 20 November 2011 - 06:47 PM

Lots of info on the net. Google is your friend!

Anyways this should work:
for /f "tokens=1-5 delims=/ " %%d in ("%date%") do md c:\TEST\TTT\%%f.%%e.%%g
for /f "tokens=1-5 delims=/ " %%d in ("%date%") do md c:\TEST\TTT\%%e.%%f.%%g

Was This Post Helpful? 1
  • +
  • -

#4 naveed_786  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 306
  • Joined: 13-October 09

Re: SET Date in Batch File

Posted 21 November 2011 - 12:15 AM

Now it makes the folder fine but when i run this command then it didn't go to 21.11.2011 folder what should i do now???

exp userid=HR/HR@oracledump file="c:\ORABACKUP\PERM\%%f.%%e.%%g"\HR.DMP log="c:\ORABACKUP\PERM\%%f.%%e.%%g\HR%fdate%%ftime%.log

Was This Post Helpful? 0
  • +
  • -

#5 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,277
  • Joined: 28-March 11

Re: SET Date in Batch File

Posted 21 November 2011 - 02:59 PM

Where does it go? What is between the code where you make the directory and this:
exp userid=HR/HR@oracledump file="c:\ORABACKUP\PERM\%%f.%%e.%%g"\HR.DMP log="c:\ORABACKUP\PERM\%%f.%%e.%%g\HR%fdate%%ftime%.log


I am rusty in batch files, but I believe if you have something between them, then the vars gets ruined.
Was This Post Helpful? 0
  • +
  • -

#6 naveed_786  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 306
  • Joined: 13-October 09

Re: SET Date in Batch File

Posted 22 November 2011 - 01:05 AM

Actually you didn't understand here is the whole code in batch file


for /f "tokens=1-5 delims=/ " %%d in ("%date%") do md c:\ORABACKUP\PERM\%%f.%%e.%%g
exp userid=HR/HR@dummy file=c:\ORABACKUP\PERM\%%f.%%e.%%g\HR.DMP


it makes the directory fine and also it finds the path like this "c:\ORABACKUP\PERM" but it didn't find complete path

file=c:\ORABACKUP\PERM\%%f.%%e.%%g

i mean it didn't find date folder(22.11.2011)
Was This Post Helpful? 0
  • +
  • -

#7 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,277
  • Joined: 28-March 11

Re: SET Date in Batch File

Posted 22 November 2011 - 04:32 PM

you have to save the "date" to a variable first, we will call it 'today':
@ECHO off
for /f "tokens=1-5 delims=/ " %%d in ("%date%") do set today=%%f.%%e.%%g
echo %today%


this is wrong as you can see from the print out:
set file=c:\ORABACKUP\PERM\%%f.%%e.%%g
echo %file%


So, use the today variable to "find the complete path":
set file=c:\ORABACKUP\PERM\%today%
echo %file%


Understand?
Was This Post Helpful? 2
  • +
  • -

#8 naveed_786  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 306
  • Joined: 13-October 09

Re: SET Date in Batch File

Posted 24 November 2011 - 03:51 AM

Thanks it really helped me.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1