Solved

How to get the 'Day of the Week' ie) monday, tuesdat etc... into a variable in batch script

Posted on 2007-03-23
3
304 Views
Last Modified: 2013-12-26
Hi,

I need to set a variable to the actual day of the week like Monday, Tuesday etc.... then on the very last line of my code I need to put that variable in place of FRIDAY which is hard coded.  How can I do that?  Here is my code:

for /F "tokens=2-4 delims=/- " %%A in ('date /t') do (
set MM=%%A
SET DD=%%B
SET YYYY=%%C
)

mkdir F:\cognos\backups\%YYYY%%MM%%DD%
cd F:\cognos\backups\%YYYY%%MM%%DD%

REM Erase all the .bak, .xml and .lae files in the F:\cognos\backups\%YYYY%%MM%%DD%. Needed in case backup is run twice.

erase F:\cognos\backups\%YYYY%%MM%%DD%\*.bak /S/Q/F
erase F:\cognos\backups\%YYYY%%MM%%DD%\*.xml /S/Q/F
erase F:\cognos\backups\%YYYY%%MM%%DD%\*.lae /S/Q/F

REM Stop the IWR Service as it cannot be running for next two steps
net stop "Cognos IWR Service Manager (cer3)"

REM First create the iwrdbbackup.bak file with the osbackup command
f:\odi\ostore\bin\osbackup -f f:\cognos\backups\%YYYY%%MM%%DD%\iwrdbbackup.bak -i f:\cognos\backups\%YYYY%%MM%%DD%\inc.lst -I "f:\cognos\backups\import_list.txt"

REM Next create the iwrdbbackup.xml file with the dsdump command
"f:\Program Files\cognos\cer3\bin\dsdump.exe" -db "F:\Program Files\Cognos\cer3\iwr\database\iwr70.db" -fn f:\cognos\backups\%YYYY%%MM%%DD%\iwrdbbackup.xml -v all -l "f:\cognos\backups\logfile.txt"

REM Copy the .db and the .pkg files
xcopy "F:\Program Files\cognos\cer3\iwr\database\"*.db F:\cognos\backups\%YYYY%%MM%%DD%\*.* /Y

REM xcopy F:\Program Files\cognos\cer3\iwr\database\*.pkg F:\cognos\backups\%YYYY%%MM%%DD%\*.* /Y

REM Start the IWR Service
net start "Cognos IWR Service Manager (cer3)"

REM Create the UpfrontStore.bak file. Cognos IWR Service can be running
"f:\Program Files\Cognos\cer3\bin\upfdbadm.exe" -b f:\cognos\backups\%YYYY%%MM%%DD%\UpfrontStore.bak

call setenv.cmd

%costar_cog_home_drive%

cd %costar_cog_home_path%\scripts\Backup Jobs

call "BACKUP_LAE.MCX"
if errorlevel 1 goto err

REM call CleanupDistributedReports.MCX
goto ok

:err
Echo Process Failed at %process_loc%
exit 1

:ok
Echo Process completed Successfully


xcopy F:\cognos\backups\%YYYY%%MM%%DD%\*.* F:\cognos\backups\Cognos7_Daily_Backups\Friday\*.* /Y
0
Comment
Question by:elwayisgod
  • 2
3 Comments
 
LVL 30

Accepted Solution

by:
SteveGTR earned 50 total points
ID: 18783115
Here's some code. Please check the spellings on the days of the week.

@echo off

setlocal

call :GETDATEPARTS "%date%"

call :GETDAY %mm% %dd% %yy%

echo Today is: %day%

goto :EOF

:GETDATEPARTS

set dt=%~1
set tok=1-3

if "%dt:~0,1%" GTR "9" set tok=2-4

set yyyy=

for /f "tokens=%tok% delims=.:/-, " %%a in ('echo %~1') do (
  for /f "skip=1 tokens=2-4 delims=/-,()." %%x in ('echo.^|date') do set %%x=%%a&set %%y=%%b&set %%z=%%c
)

if not "%yyyy%"=="" set yy=%yyyy%

if 1%yy% LSS 1000 (if %yy% LSS 70 (set yy=20%yy%) else (set yy=19%yy%))
if 1%mm% LSS 100 set mm=0%mm%
if 1%dd% LSS 100 set dd=0%dd%

goto :EOF

:GETDAY

if "%~3"=="" echo GETDAY requires 3 parameters: mm dd yy (4 digit)&goto :EOF

set wmm=%1
set wdd=%2
set wyyyy=%3

if 1%wmm% GTR 100 set /A wmm=1%wmm% - 100
if 1%wdd% GTR 100 set /A wdd=1%wdd% - 100

if %wmm% LSS 3 set /a wmm+=12&set /a wyyyy-=1

set /A dayNum=%wdd% + (2 * %wmm%) + (3 * (%wmm% + 1) / 5) + %wyyyy% + (%wyyyy% / 4) - (%wyyyy% / 100) + (%wyyyy% / 400) + 1
set /A dayNum=%dayNum% %% 7

if %dayNum%==0 set day=Sunday
if %dayNum%==1 set day=Monday
if %dayNum%==2 set day=Tuesday
if %dayNum%==3 set day=Wednesday
if %dayNum%==4 set day=Thursday
if %dayNum%==5 set day=Friday
if %dayNum%==6 set day=Saturday

goto :EOF

Good Luck,
Steve
0
 

Author Comment

by:elwayisgod
ID: 18783526
Is that as short as the code can get?
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 18783585
yup
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now