I created a date checker but when I run it it displays wrong info

Viewed 32

So I got a code that checks for the weekday and then uses it to do other things. But there's a problem that (lets say today is Monday) when I run the code on my pc it says Mo (correct), but when I run it on my laptop it says 20 (not correct), can somebody help? This is the code :

@echo off
set day=%date:~0,2%
echo %day%
pause
1 Answers

The best and the correct method to get this is to use the date independently of the region day/month order, you can use "WMIC os GET LocalDateTime /Value" and WMIC Path Win32_LocalTime GET DayOfWeek /value as a source, since it's in ISO order:


@echo off & setlocal
Title Get the date and time independently of the region using WMIC
@for /f %%i in (
'WMIC OS GET LocalDateTime /value ^& WMIC Path Win32_LocalTime GET DayOfWeek /value'
) do (
    @for /f %%j in ("%%i") do set "%%j" & echo "%%j"
)

Set /a "tok=DayOfWeek+1"
@for /f "tokens=%tok%" %%i in (
"Sunday Monday Tuesday Wednesday Thursday Friday Saturday"
) do (
    Set "Day=%%i"
    Set "D=%LocalDateTime:~6,2%"
    Set "M=%LocalDateTime:~4,2%"
    Set "yyyy=%LocalDateTime:~0,4%"
    Set "hh=%LocalDateTime:~8,2%"
    Set "mm=%LocalDateTime:~10,2%"
    Set "ss=%LocalDateTime:~12,2%"
)
echo( Created: %Day% the %D%/%M%/%yyyy% at %hh%:%mm%:%ss%
pause
Related