Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dos Command - Date/Time

Status
Not open for further replies.

hi2jenny

Programmer
Mar 30, 2005
14
US
Is there a way to get date and time in DOS? I tried "date". but it prompts me to set a new date. In fact, I want to write a batch script to copy a file with the current date and time as the filename (the latest file in a directory) to another network drive. This batch will be scheduled to run every night at 12. Please tell me any way to do it. Thanks!
 
hi2jenny,
there are a few ways to do it, vba (is office on the box?), automation (nifty little program if you can spend the $) and i'm sure dos. any proference?
regards,

longhair
 
No, MS Office is not installed on the server. And I do prefer to to use DOS and create a batch to do it. Any suggestion to do so?
 
hi2jenny,
this should get you started - they're login batch scripts that i use but you should be able to modify:
create login1.bat and put the following in it:
@echo off
echo ****************************** >> C:\login.log
echo. | date | find "bootlog.log" >> C:\login.log
echo. | time | find "bootlog.log" >> C:\login.log
call login2.bat
echo Login occured at %date% %time% >> c:\login.log
net config workstation | find "User" >> C:\login.log
echo ****************************** >> C:\login.log
cls
create login2.bat and put the follwoing in it:
if "%3"=="" goto GETDATE
if "%4"=="" goto SETTIME
goto SETDATE
:SETTIME
set TIME=%3
goto DONE
:SETDATE
set DATE=%4
goto DONE
:GETDATE
echo.|date>temp.bat
call temp.bat
echo.|time>temp.bat
call temp.bat
if exist temp.bat del temp.bat
goto DONE
:DONE
change the file name to what you want to use to keep a log. remove the 'net cofig' line if you don't need and put your rename and move commands before the 'cls' line.
hth
regards,
longhair
 
thank you very much, longhair. I will try to digest.
 
Here's one that I use to output today's date as YYMMDD format to a file called today.txt. I use this for having the correct date so I can pickup the correct IIS log file (exYYMMDD.log).
Code:
@echo off
FOR /F "TOKENS=1-3* DELIMS=/" %%A IN ('DATE/T') DO (
	SET Year=%%C
	SET Month=%%B
	SET Day=%%A
)
FOR %%A IN (%Day%) DO SET WDay=%WDay%%%%A
FOR %%A IN (%Year%) DO SET WYear=%WYear%%%%A
for /f "tokens=2 delims=0" %%i in ('echo %WYEAR%') do set NYear=0%%i

SET TEXTDATE=%NYear%%MONTH%%WDAY%
ECHO %TEXTDATE% > today.txt

SET TEXTDATE=
SET YEAR=
SET WYear=
SET MONTH=
SET WDAY=
SET DAY=
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top