Is there a way to get epoch time using a dos command? If not, can the date, time dos command output be modified?
For e.g Date in dos gives the date with / etc. I would like to get an output that has no special characters such as / :
Is there a way to get epoch time using a dos command? If not, can the date, time dos command output be modified?
For e.g Date in dos gives the date with / etc. I would like to get an output that has no special characters such as / :
Try this:
for /F "tokens=2-4 delims=/ " %i in ('date /t') do echo %k%i%j
More on:
from the command line try this
for /f "tokens=2,3,4 delims=/ " %f in ('date /t') do @echo %h%g%f
remember to double up the % chars if in batch file
@echo off
setlocal
for /f "tokens=2,3,4 delims=/ " %%f in ('date /t') do set d=%%h%%g%%f
for /f "tokens=1,2 delims=: " %%f in ('time /t') do set t=%%f%%g
echo datetime is : %d%%t%
endlocal
I got this output:
c:\development>xx.bat
datetime is : 201008111108
There is no reliable way of getting a date in batch files without resorting to external tools or other languages such as VBScript.
From VBScript you can access the current date and time with the Date
and Time
functions. FormatDateTime
will get you a culture-neutral date/time format which you can then parse.
You can get a result frmo the VBScript by using WScript.Echo
from within the script and calling it like so from the batch:
for /f "delims=" %%x in ('cscript /nologo foo.vbs') do set result=%%x
Then the variable %result%
contains whatever the VBScript had as output in its first line.