Page 1 of 1
date not showing
Posted: 11 Oct 2019 13:00
by jap
Hi,
any idea why the date does not show up in one pc? other pc when i run this batch included in my script it runs fine
@echo off
for /F "tokens=2" %%i in ('date /t') do set mydate=%%i
set mytime=%time%
echo Current time is %mydate%:%mytime%
turned off uac
pc's running on windows 10
Re: date not showing
Posted: 11 Oct 2019 14:44
by Compo
The returned date from
date /t is not consistent across PC's or users. I'm assuming that you were previously seeing
ddd and trying to ignore it by selecting the second token. You can still use the same method, if you like, by just checking for an empty value for the second token:
Code: Select all
For /F "Tokens=1*" %%A In ('Date /T') Do If "%%B"=="" Set "mydate=%%A" Else Set "mydate=%%B"
Re: date not showing
Posted: 11 Oct 2019 18:25
by Hackoo
I recommend you using 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:
Code: Select all
@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%]
pause
Refer to this Source
https://stackoverflow.com/questions/203 ... ve#tab-top
Re: date not showing
Posted: 14 Oct 2019 10:03
by jap
Hackoo wrote: ↑11 Oct 2019 18:25
I recommend you using 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:
Code: Select all
@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%]
pause
Refer to this Source
https://stackoverflow.com/questions/203 ... ve#tab-top
this was the solution - WMIC os GET LocalDateTime
thanks Hackoo!