ROM
ReadOnlyMaio
  • Links
  • Linux Quick Command Reference
  • MaxDB Quick Command Reference
  • MSSQL Quick Command Reference
  • Oracle Quick Command Reference
  • Powershell Quick Command Reference
  • Private – Piteco
  • Private Download
  • Windows CMD quick command reference

Tag: timestamp

Create a timestamp in YYYYMMDD_HHMMSS format with CMD or Powershell

Posted on April 22, 2017 by MaioLeave a comment on Create a timestamp in YYYYMMDD_HHMMSS format with CMD or Powershell

Using CMD

FOR /f %a IN ('WMIC OS GET LocalDateTime ^| FIND "."') DO SET DTS=%a
SET TIMESTAMP=%DTS:~0,8%_%DTS:~8,6%

Check your result:

C:\>ECHO %TIMESTAMP%
20170422_233337

If you’re going to use the instructions above in a batch file remember to change the “%a” token in “%%a”.

Using Powershell

get-date -f yyyyMMdd_HHmmss

To set a timestamp variable:

$timestamp = get-date -f yyyyMMdd_HHmmss
echo $timestamp
20170423_001455
Posted in WindowsTagged cmd, hhmmss, timestamp, yyyymmdd

Categories

  • Linux
  • MSSQL
  • Nerd Stuff
  • Oracle
  • Powershell
  • SAP
  • Sybase
  • Windows
Proudly powered by WordPress
Simple White lite RGB Classic