:: Checkinn.bat
:: With thanks to Dias De Verano for his assistance.
@echo off & setlocal enabledelayedexpansion
cls
:: Create/run vbs file (extracts date components) & set variables..
set vbsfile=%temp%\newdate.vbs
echo Newdate = (Date())>%vbsfile%
echo Yyyy = DatePart("YYYY", Newdate)>>%vbsfile%
echo Mm = DatePart("M" , Newdate)>>%vbsfile%
echo Dd = DatePart("D" , Newdate)>>%vbsfile%
echo Wd = DatePart("WW" , Newdate)>>%vbsfile%
echo Wn = DatePart("Y" , Newdate)>>%vbsfile%
echo Ww = datepart("W" , Newdate)>>%vbsfile%
echo Wscript.Echo Yyyy^&" "^&Mm^&" "^&Dd^&" "^&Wd^&" "^&Ww^&" "^&Wn>>%vbsfile%
FOR /F "tokens=1-6 delims= " %%A in ('cscript //nologo %vbsfile%') do (
set weekday#=%%E
)
del %vbsfile% & set vbsfile=
for /f "tokens=1-3 delims=: " %%A in ('time/t') do (
set hour=%%A
set mins=%%B
set ampm=%%C
)
set hourmins=%hour%%mins%
: Set shift identifier based on time of day:
set shift=A
if "%ampm%"=="PM" if %hourmins% gtr 0200 if %hourmins% lss 1001 (
set shift=B & goto next
)
if "%ampm%"=="PM" if %hourmins% gtr 1000 if %hourmins% lss 1201 (
set shift=C & goto next
)
if "%ampm%"=="AM" if %hourmins% lss 0401 (
set shift=C
set /a weekday# -=1
if !weekday#! lss 1 set weekday#=7 & goto next
)
if "%ampm%"=="AM" if %hourmins% gtr 1159 (
set shift=C
set /a weekday# -=1
if !weekday#! lss 1 set weekday#=7
)
:next
:: Set alpha day from the week day number:
for /f "tokens=%weekday#%" %%a in ("Sun Mon Tues Wed Thu Fri Sat") do (
set alfaday=%%a
)
:: Environment Variables set are:
:: %weekday#% = Day number within week (range 1 thru' 7, Sun is day #1)
:: %alfaday% = Alpha day (range Sun thru' Sat)
:: %hour% = Hour of the day
:: %mins% = Minutes of the hour
:: %ampm% = AM or PM indicator
:: %shift% = Shift identity letter ( range A thru C)
:: Display for checking purposes:
echo.&echo.&echo.&echo.&echo.&echo.&echo.
echo Today's date is %date%
echo Current time is %hour%:%mins% %ampm%
echo.
echo Day number of week = %weekday#% Alpha day = %alfaday%
echo.
echo AM or PM = %ampm%
echo.
echo Hour plus mins = %hourmins% Shift identifier = %shift%
echo.&echo.
echo After checking the displayed output press any key
echo to continue...
set shift=
echo.&echo.&echo.&echo.&echo.&echo.&echo.
pause > nul
cls
endlocal
exit /b