Question: Can anyone help me debug / correct this batch file? :: Extract components from the date and time for / f tokens = 1 -

Can anyone help me debug/correct this batch file?
:: Extract components from the date and time
for /f "tokens=1-4 delims=/"%%a in ('date /t') do (
:: Store day of week
set dayOfWeek=%%a
:: Store month
set month=%%b
:: Store the day
set day=%%c
:: Store the year
set year=%%d
)
for /f "tokens=1-2 delims=:"%%x in ('time /t') do (
:: Store the hour
set hour=%%x
:: Store the minutes
set minute=%%y
)
:: Get 3 letter day name
set day1=%date:~0,3%
:: Create map for 3 letter name to full name
set map=Mon-Monday;Tue-Tuesday;Wed-Wednesday;Thu-Thursday;Fri-Friday;Sat-Saturday;Sun-Sunday
call set day1=%%map:*%day1%-=%%
:: Convert 3 letter name to full name
set day1=%day1:;=&rem.%
:: Get the month number
set monthName=%date:~4,2%
:: Create map for month number to full month name
set map1=01-January;02-February;03-March;04-April;05-May;06-June;07-July;08-August;09-September;10-October;11-November;12-December
call set monthName=%%map1:*%monthName%-=%%
:: Convert the month number to the full month name
set monthName=%monthName:;=&rem.%
:: Convert 24-hour format to 12-hour format and determine period of the day
set /A "hourMod=100%hour%%%100"
if %hourMod% geq 12(
set period=PM
if %hourMod% gtr 12(
set /A hourMod-=12
)
) else (
set period=AM
)
:: Handle 24h format midnight (00:00)
if %hourMod%==0 set hourMod=12
:: Determine morning, afternoon, or evening
if %hour% lss 12(
set timeOfDay=morning
) else if %hour% lss 18(
set timeOfDay=afternoon
) else (
set timeOfDay=evening
)
:: Display the message
echo Hello %username%.
echo Today's date is %dayOfWeek%%month%/%day%/%year%
echo It is currently %hourMod%:%minute%%period%
echo.
echo Today is %day1% and it is %monthName%%day%,%year%.
echo Have a wonderful %timeOfDay%^^!
It currently works, however the message displayed at the end of the script says both am and pm simultaneously, and always says have a wonderful morning regardless of the time of day it's executed.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!