title: Filename timestamp in Windows CMD batch script getting truncated
body: <p>I have a batch script that outputs a file, and I'm trying to ensure that each time the script is executed, no existing files are overwritten, so I'm trying to put a timestamp on it.</p>
  
  <p>Currently I have this:</p>
  
  <pre><code>set  stamp=%DATE:/=-%_%TIME::=-%
  </code></pre>
  
  <p>But if the time is 1-9&nbsp;AM, it gives something like:</p>
  
  <pre><code>13-06-2012_ instead of a full 13-06-2012_12-39-37.28
  </code></pre>
  
  <p>How can I fix this?</p>
  
  <p>I'm using Windows&nbsp;7, and the output of <code>echo %date% %time%</code> in a command line window is (my clock format for 'short date' is set to display 3-letter months):</p>
  
  <pre><code>03-Sep-12 9:06:21.54
  </code></pre>
  
  <p>Basically I want a solution that solves the issue regardless of what the clock  format is set to.</p>
  
  <hr>
  
  <p><strong>Edit:</strong> Since no one likes to read past the title, I will explicitly state this question is about a truncation issue. And I found a solution.</p>
  
  <p>I've been using the following timestamp for a good while now, works well.</p>
  
  <pre><code>set timestamp=%DATE:/=-%_%TIME::=-%
  set timestamp=%timestamp: =%
  </code></pre>
  
  <p>It produced a timestamp like: <code>18-03-2013_13-37-43.26</code>, by replacing <code>/</code> and <code>:</code> in <code>%TIME%</code> and <code>%DATE%</code>, then stripping white space. The whitespace was the problem in my original question, really.</p>