Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
329 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 200 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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
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)
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

721 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