Batch script: creating a time stamp

Posted on 2006-05-22
Last Modified: 2013-12-03
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.

Question by:gromul
    LVL 95

    Accepted Solution

    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
    LVL 86

    Expert Comment

    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%

    Author Comment


    Author Comment


    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
    For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now