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
316 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

632 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