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
date not showing
Moderator: DosItHelp
Re: date not showing
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
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:
Refer to this Source https://stackoverflow.com/questions/203 ... ve#tab-top
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
Re: date not showing
this was the solution - WMIC os GET LocalDateTimeHackoo wrote: ↑11 Oct 2019 18:25I 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:Refer to this Source https://stackoverflow.com/questions/203 ... ve#tab-topCode: 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
thanks Hackoo!