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
309 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Python variable _ manually assigned 9 86
Need some help with powershell script 5 50
"Black Box" Testing of Control System Software 2 52
ROBOFTP UNZIP 1 46
In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

810 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