Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to print month name in file name by using bat

Tags:

batch-file

I want to use the month name in the file name. i am exporting the data from sql server the name of the file should use the system date if the month is 3 three then it should print the file name as febact,if the month is 4 then it should print marchact.

Thanks, Ravi.

like image 500
user2172165 Avatar asked Nov 30 '22 13:11

user2172165


1 Answers

You have not provided the format of your file name. The Batch file below just converts the month of current date:

@echo off
setlocal EnableDelayedExpansion
set m=100
for %%m in (January February March April May June July August September October November  December) do (
   set /A m+=1
   set month[!m:~-2!]=%%m
)
rem Change tokens=2 for DD/MM/YYYY date format
for /F "tokens=1 delims=/"  %%m in ("%date%") do (
   set monthName=!month[%%m]!
)
echo %monthName%

If you want month name have constant length (ie: 3 letters):

@echo off
setlocal EnableDelayedExpansion
for /F "tokens=1 delims=/" %%m in ("%date%") do (
   set /A "m=(1%%m%%100-1)*3"
)
set month=JanFebMarAprMayJunJulAugSepOctNovDec
set monthName=!month:~%m%,3!
echo %monthName%

Antonio

like image 175
Aacini Avatar answered Mar 06 '23 22:03

Aacini