Update CSV file column with current date

April 5, 2011 at 17:41:18
Specs: Windows 7
I would like to create a bat or vbs script to update the date in a CSV file to the current date. The Date column is in the 16th column of the file. The filename is Mailing.cvs. Any help would be greatly appreciated.

See More: Update CSV file column with current date

Report •


#1
April 6, 2011 at 15:44:18
Try this lazy way, tested briefly only on Win XP.

Input data file Mailing.cvs:

1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,date today ,17,18
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,todays date,17,18

Batch script:

@echo off>mailing1.cvs
cls
setlocal enabledelayedexpansion

for /f "tokens=1-16* delims=," %%A in (mailing.cvs) do (
    set col1=%%A,%%B,%%C,%%D,%%E,%%F,%%G,%%H,%%I,%%J,%%K,%%L,%%M,%%N,%%O,
    set col2=%%Q
    echo !col1!%date%,!col2!>>mailing1.cvs
)
type mailing1.cvs

Output data file Mailing1.cvs:

1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,Thu 07/04/2011,17,18
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,Thu 07/04/2011,17,18

If you require the date in a different format you'll have to set and save that format.

Good luck, hope this helps.

Did you Google for an answer before asking the question?


Report •

#2
April 9, 2011 at 20:32:29
I have tried this (Windows 7) and even after changing the extensions to CSV it is not working, I must be missing something.

I appreciate your help. Thank you.


Report •

#3
April 10, 2011 at 02:49:43
What do you mean by "it is not working"? What result(s) do you get, any error messages?

Perhaps there are differences between XP and Win 7.

Did you Google for an answer before asking the question?


Report •

Related Solutions

#4
April 10, 2011 at 16:47:47
I post the batch file in the same directory as the csv file and double click it, There is a brief change in the screen like the batch file ran. When I open the mailing .csv it has not updated the date.

I don't get any error messages.


Report •

#5
April 11, 2011 at 03:45:13
Well, the script you are using does not update mailing.csv it creates a new updated file mailing1.csv which you will see if you add a Pause command as the last line of the script.

Did you Google for an answer before asking the question?


Report •

Ask Question