Solved CMD Inserting a line but changing date every day.

December 4, 2012 at 02:39:07
Specs: windows 7
Hi there,

I have a batch file, it's adding a text line every day (see below) to a csv file.
In the line there is a date, this date has to be changed each day and it's has to be the date of yesterday. And on Monday it's has to be the date of Friday. When the date change is done, the line has to be added in the file.

I don't know how to do it, i know there are commando's to change date. I have searched on internet and on this forum but i could not find it. Hope that some body can help me.

for %%j in (C:\blp\bbdl\_csv\dailycurrency1.out.????????.csv) do @echo."EUR CMPN Curncy|0|4|EUR|12/03/2012|Composite(NY)|1.000000|">> %%j

See More: CMD Inserting a line but changing date every day.

Report •

December 4, 2012 at 10:18:19
No luck this time since in batch script there is no simple way to manipulate date. The required code becomes awesomely complex and unreadable. Sorry nothing to do.

Report •

December 4, 2012 at 18:22:31
✔ Best Answer
If you can use vbscript, this might work:
'==== begin vbscript d8.vbs
'(cut/paste the next two lines into notepad and save as: "d8.vbs")
if datepart("w",wscript.arguments(0),vbMonday)=1 then adder=-3 else adder=-1
wscript.echo dateadd("d",adder,wscript.arguments(0))
'==== end vbscript

To use from batch:
for /f %%a in ('cscript d8.vbs %date:~4%') do set lbd=%%a

If you are forbidden to use vbscript, I did write a somewhat lengthy and cumbersome (Ivo is right about that) batch routine to try and work it.

Report •

December 4, 2012 at 22:04:55
It might be easier to just go with the most recent file.

How To Ask Questions The Smart Way

Report •
Related Solutions

Ask Question