MS-DOS tips for time and date stamps
We have a help rendition system internally, where all we writers do is
create the source files needed to make CHM files (HHK, HHC, HHP, HTML), zip
up the HTML source in a certain way with a certain file name, and submit it
using a webform. Out of that rendition engine we can get CHM,
JavaHelp,WinHelp, NetHelp, or our internally-created cross-platform help
called Browser Help. Browser Help is the system that works with BMC
Performance Manager and I've posted before about
how to create those help systems automatically.
Since I needed to render several help systems at once, meaning I had to make multiple zip files containing the right content with the right zip file name, and I dislike tedious repetitive tasks, but somehow I like the tedium of testing and using scripts, I used DOS batch files to do the file creation and name formatting for me.
Today's tip is how to make folders with a date and time stamp as the
folder name. Our rendition engine likes its zip files with a certain naming
convention. As an added bonus, this routine works before and after ten in
the morning. Silly DOS, it doesn't put a leading zero in unless you tell it
to. Here's how to tell DOS to put in the leading zero if the current time is
prior to 10:00am.
REM Create sub directory called \yymmdd_hhmmss
REM where yymmdd_hhmmss is a date_time stamp like 030902_134200
set hh=%time:~0,2%
REM Since there is no leading zero for times before 10 am, have to put in
REM a zero when this is run before 10 am.
if "%time:~0,1%"==" " set hh=0%hh:~1,1%
set yymmdd_hhmmss=%date:~12,2%%date:~4,2%%date:~7,2%_%hh%%time:~3,2%%time:~6,2%
md h:\%yymmdd_hhmmss%
A Command-line reference A-Z that contains all the reference information for DOS command-line parameters is available on the Microsoft site.
_____
tags:
MS-DOS Tips for Time and Date Stamps
Here is the line which renames the file:
ren dtfile1.txt DATA-%date:~-4,4%%date:~-10,2%%date:~-7,2%-%time:~-11,2%%time:~-8,2%%time:~-5,2%.txt
As long as we do the action after 10:00 AM, it works fine, otherwise, it does not work because it finds a space where a digit should be. Attempts to make the machine always see "military time" don't work.
Replies to this comment
-
Replies to this comment
MS-DOS
I need one more help from you, I pass password as a parameter to my batch file, when password contains “=”, “%”, “&” batch file throwing password not correct error, how can tell to ignore these characters?
yeah
Date Script
help
Ex. 2007-05-08_05.30.12
NEED SUM HELP..!!!
set hh=%time:~0,2%
if "%time:~0,1%"==" " set hh=0%hh:~1,1%
set yyyy-mm-dd__hh.mm.ss=%date:~10,4%-%date:~4,2%-%date:~7,2%__%hh%.%time:~3,2%.%time:~6,2%---%date:~-0,3%
MD c:\%yyyy-mm-dd__hh.mm.ss%
Gives me Folder Names like this: 2007-05-09__22.17.28---Wed
So my next question would be:
Is it possible to change the time from 24H time to 12H time and Have it insert AM or PM into the time-stamp so it would look like this:
2007-05-09__12.17.28.AM---Wed
2007-05-09__12.17.28.PM---Wed
2007-05-09__01.17.28.AM---Wed
2007-05-09__01.17.28.PM---Wed
Replies to this comment
File creation date
Great info
Internationalisation
e.g.
US will have date MM/DD/YYYY
UK will have date DD/MM/YYYY
Replies to this comment
Thanks
Thank you
Thank you
Great Script!
Very helpful, thank you
set orig_dir=%cd%
cd \some_other_dir
cd %orig_dir%
Replies to this comment
Dates in file names
Replies to this comment
date time stamp file names
the hours of 00:00:00 and 01:00:00.
Replies to this comment
Thank you.
Perfect, just what we needed
We used (on an Australian regional settings XP server):
SET newfilename=%DATE:~4,2%%DATE:~7,2%%DATE:~10,4%
And then wrote to the file via pipe e.g. scripted output > %filename%.txt
Cheers, Dugald.
Date Time Stamp
set YY=%date:~2,2%
set MM=%date:~0,2%
set DD=%date:~7,2%
Defining time worked fine.
used dos date & time script
timestamp
I had forgotten that environment variables could be manipulated this way.
For anyone interested, here's timestamp:
set TIMESTAMP=%date:~10,4%_%date:~4,2%_%date:~7,2%_%time:~0,2%_%time:~3,2%_%time:~6,2%
C:\win32\timestamp>echo %TIMESTAMP%
2008_05_08_11_02_03
Replies to this comment
Timestamp ex. 20080510_082233
set timestamp=%time:~0,8%
if @%timestamp:~0,1% == @ set timestamp=0%timestamp:~1,7%
set timestamp=%date:.=%_%timestamp::=%
echo.Timestamp :: %timestamp%
syntax incorrect
REM Create sub directory called \yymmdd_hhmmss
REM where yymmdd_hhmmss is a date_time stamp like 030902_134200
set hh=%time:~0,2%
REM Since there is no leading zero for times before 10 am, have to put in
REM a zero when this is run before 10 am.
if "%time:~0,1%"==" " set hh=0%hh:~1,1%
set yymmdd_hhmmss=%date:~12,2%%date:~4,2%%date:~7,2%_%hh%%time:~3,2%%time:~6,2%
md C:\%yymmdd_hhmmss%
and modified only the drive path and when run the file generates the following error:
The syntax of the command is incorrect.
Any ideas? Seems like this worked for everyone else quite well.
Thank you
Thank you
You made my day!!
Replies to this comment
Thank You!
Thank you so much!
Replies to this comment
Thanks
Great Code
Thank you very much for the wonderful code.
That worked like a champ.
-Regards,
Sudhakara.T.P.



But, I needed a yyyy version!!!
So, I did ended up with the following.
REM'd the yymmdd SET and replaced it with a SET YYYYMMDD and then diddled with the offset's in the parsing routine.
REM set yymmdd_hhmmss=%date:~12,2%%date:~4,2%%date:~7,2%_%hh%%time:~3,2%%time:~6,2%
SET YYYYMMDD_HHMMSS=%DATE:~6,4%%DATE:~0,2%%DATE:~3,2%_%HH%%TIME:~3,2%%TIME:~6,2%
Thanks for this handy DOS script to set the environment variabel, and allowing me to create a file name with a timestamp!!
Replies to this comment