Last active
May 23, 2024 06:14
-
-
Save KenDB3/2ea86c9d82c0d14aacb1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
REM Create variables that store Weekday (WD), Day (D), Month (M), and the 4-digit Year (Y) | |
for /F "tokens=1-4 delims=/ " %%i in ('date /t') do ( | |
set WD=%%i | |
set D=%%j | |
set M=%%k | |
set Y=%%l | |
) | |
REM Create variables that store Hour (H for Military or Hr for 12-hour with AM/PM), Minute (Mn), and AM/PM (AP) | |
for /F "tokens=1-4 delims=: " %%i in ('time /t') do ( | |
set H=%%i | |
set Hr=%%i | |
set Mn=%%j | |
set AP=%%k | |
) | |
REM Use this if you like a 2-digit year instead of 4-digit year | |
set yearxx=%DATE:~12,2% | |
REM Make the "H" variable set as correct Military Time if "AP" variable came up as PM. | |
REM Noting that 12 is a special case either way. | |
if not %H%==12 if "%AP%"=="PM" set /A H=%H%+12 | |
if "%AP%"=="AM" if "%H%"=="12" set /A H="00" | |
REM This ensures H has a two digit hour, even if it is less than 10. | |
set H=00%H% | |
set H=%H:~-2% | |
REM This one looks like: "Fri 01/01/2016 - 23:59" | |
echo %WD% %D%/%M%/%Y% - %H%:%Mn% | |
echo or... | |
REM This one looks like: "Fri 01/01/16 - 11:59 PM" | |
echo %WD% %D%/%M%/%yearxx% - %Hr%:%Mn% %AP% | |
pause |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment