Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 54643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:15:08+00:00 2026-05-10T17:15:08+00:00

Update: Now that it’s 2016 I’d use PowerShell for this unless there’s a really

  • 0

Update: Now that it’s 2016 I’d use PowerShell for this unless there’s a really compelling backwards-compatible reason for it, particularly because of the regional settings issue with using date. See @npocmaka’s https://stackoverflow.com/a/19799236/8479


What’s a Windows command line statement(s) I can use to get the current datetime in a format that I can put into a filename?

I want to have a .bat file that zips up a directory into an archive with the current date and time as part of the name, for example, Code_2008-10-14_2257.zip. Is there any easy way I can do this, independent of the regional settings of the machine?

I don’t really mind about the date format, ideally it’d be yyyy-mm-dd, but anything simple is fine.

So far I’ve got this, which on my machine gives me Tue_10_14_2008_230050_91:

rem Get the datetime in a format that can go in a filename. set _my_datetime=%date%_%time% set _my_datetime=%_my_datetime: =_% set _my_datetime=%_my_datetime::=% set _my_datetime=%_my_datetime:/=_% set _my_datetime=%_my_datetime:.=_%  rem Now use the timestamp by in a new ZIP file name. 'd:\Program Files\7-Zip\7z.exe' a -r Code_%_my_datetime%.zip Code 

I can live with this, but it seems a bit clunky. Ideally it’d be briefer and have the format mentioned earlier.

I’m using Windows Server 2003 and Windows XP Professional. I don’t want to install additional utilities to achieve this (although I realise there are some that will do nice date formatting).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T17:15:08+00:00Added an answer on May 10, 2026 at 5:15 pm

    See Windows Batch File (.bat) to get current date in MMDDYYYY format:

    @echo off For /f 'tokens=2-4 delims=/ ' %%a in ('date /t') do (set mydate=%%c-%%a-%%b) For /f 'tokens=1-2 delims=/:' %%a in ('time /t') do (set mytime=%%a%%b) echo %mydate%_%mytime% 

    If you prefer the time in 24 hour/military format, you can replace the second FOR line with this:

    For /f 'tokens=1-2 delims=/:' %%a in ('%TIME%') do (set mytime=%%a%%b) 

    C:> .\date.bat
    2008-10-14_0642

    If you want the date independently of the region day/month order, you can use ‘WMIC os GET LocalDateTime’ as a source, since it’s in ISO order:

    @echo off for /F 'usebackq tokens=1,2 delims==' %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6% echo Local date is [%ldt%] 

    C:>test.cmd
    Local date is [2012-06-19 10:23:47.048]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 84k
  • Answers 84k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Having not been able to get Uri.EscapeDataString to take on… May 11, 2026 at 5:05 pm
  • Editorial Team
    Editorial Team added an answer yes, make a copy of the FlowDocument before printing it.… May 11, 2026 at 5:05 pm
  • Editorial Team
    Editorial Team added an answer There is such configuration in our hudson build server. In… May 11, 2026 at 5:05 pm

Related Questions

Update: Now that it's 2016 I'd use PowerShell for this unless there's a really
i've written a UserControl descendant that is in an assembly dll. How do i
I want to assert that a certain registry value exists after installation, so I
So I need a 2-dimensional ConcurrentHashMap . It has to be as blazing fast
I have a bunch of Velocity template files in a Visual Studio 2008 project,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.