I need the value of the hour and the minute value separately. I need them for some calculations.
I don't need this:
echo %date%
Output: Days/Months/Years;
echo %time%
Output Hours/Minutes/Seconds;
I need:
x
Output: Hours;
y
Output: Minutes;
I need the value of the hour and the minute value separately. I need them for some calculations.
I don't need this:
echo %date%
Output: Days/Months/Years;
echo %time%
Output Hours/Minutes/Seconds;
I need:
x
Output: Hours;
y
Output: Minutes;
This is easy enough with the PowerShell that is already on your supported Windows system.
FOR /F "delims=" %%A IN ('powershell -NoLogo -NoProfile -Command "Get-Date -Format 'HH'"') DO (SET "HOUR=%%~A")
FOR /F "delims=" %%A IN ('powershell -NoLogo -NoProfile -Command "Get-Date -Format 'mm'"') DO (SET "MINI=%%~A")
ECHO HOUR is %HOUR%
ECHO MINI is $MINI
Another way is to use WMIC.exe
, but that still requires parsing out the hour and minute using %VAR:x,y^ values. The upside is that X and Y are always the same. Using the TIME variable parsing out the hour and minute can be done. However, the user may have the hour configured to not have a leading zero if the hour is less than 10:00. And there is the problem of AM/PM.
For an extensive list of alternatives, see https://stackoverflow.com/a/19799236/447901