[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1994
  • Last Modified:

Batch script: creating a time stamp

I need a small batch script that would create a time stamp based on the current time in this format: YYYYMMDDHHmmSS. Y is for year, M for month, m for minute, etc. Can anyone help me with this? Some sample code to get me started would be helpful.

Thanks!
0
gromul
Asked:
gromul
  • 2
1 Solution
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
Assuming you have a US date  format:

ECHO %date:~-4%%date:~4,2%%date:~7,2%%time:~0,2%%time:~3,2%%time:~6,2% > file.txt
0
 
jkrCommented:
The seconds are gonna be difficult, since 'time /t' does not output them. You could use

for /F "tokens=2,3,4 delims=/. " %%i in ('date /t') do set d=%%k%%i%%j

for /F "tokens=1,2,3,4 delims=:. " %%i in ('time /t') do set t=%%i%%j%%k%%l

set timestamp=%d%%t%

echo %timestamp%
0
 
gromulAuthor Commented:
Thanks!
0
 
gromulAuthor Commented:
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now