Contoh File Bat Mendapatkan Nama Hari & Bulan

 

Contoh File bat untuk mendapatkan nama hari :

1. Get Bulan : nama file = namabulan.bat

@echo off

for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a

set year=%dt:~0,4%

set month=%dt:~4,2%

set day=%dt:~6,2%

if %month%==01 set monthname=January

if %month%==02 set monthname=Febuary

if %month%==03 set monthname=March

if %month%==04 set monthname=April

if %month%==05 set monthname=May

if %month%==06 set monthname=June

if %month%==07 set monthname=July

if %month%==08 set monthname=August

if %month%==09 set monthname=September

if %month%==10 set monthname=October

if %month%==11 set monthname=November

if %month%==12 set monthname=December


rem untuk menampilkan hasil 

echo %monthname%

rem untuk menghentikan biar bisa melihat hasil

Pause


2. Get Day Name

@echo off

REM Create VBS that will get day of week in same directory as batch

echo wscript.echo WeekdayName(Weekday(Date))>>DayOfWeek.vbs

REM Cycle through output to get day of week i.e monday,tuesday etc

for /f "delims=" %%a in ('cscript /nologo DayOfWeek.vbs') do @set dow=%%a

REM delete vbs

del DayOfWeek.vbs

REM Used for testing outputs days name

echo %dow%

REM Case of the days name is important must have a capital letter at start

REM Check days name and assign value depending

IF %dow%==Monday set downum=0

IF %dow%==Tuesday set downum=1

IF %dow%==Wednesday set downum=2

IF %dow%==Thursday set downum=3

IF %dow%==Friday set downum=4

IF %dow%==Saturday set downum=5

IF %dow%==Sunday set downum=6

rem menampilkan days number 0-mon,1-tue ... 6-sun

echo %downum%

rem menghentikan layar 

Pause