Wednesday, December 19, 2007

datestamps

hooray. I have a new job doing server/middleware support. Even better: a co-worker asked me to do something - convert a unix shell script to run on a Windows 2003 server. Aside from the lines dealing with an Oracle client - they want a datestamp in the reports:

from the familar unix one-liner:

now =`date +'%Y%m%d%M%S'`

to the following horror:

REM generate timestamp!

@for /F "tokens=2,3,4 delims=/ " %%A in ("%date%") do @(
set day=%%A
set month=%%B
set year=%%C
)
@for /F "tokens=1,2,3 delims=: " %%A in ("%time%") do @(
set hour=%%A
set minute=%%B
set sec=%%C
)
REM cleanup the seconds string
@for /F "tokens=1* delims=. " %%A in ('echo.%sec%') do @(
set sec=%%A
)

set timestamp=%year%%month%%day%%hour%%minute%%sec%

& of course, this will break if the locale is not Australian dates...yuk. Hope I'm not being naive in that. A solution might be to do more in VB (which I do know) or install Perl on everything.

No comments: