1.

Solve : Create next Wednesday Month Year?

Answer»

I so crazy with this batch code for next Wednesday/Month/YR. The code will run every Wednesday 12:01 am will create next Wednesday. So I got that part next Wednesday work fine, but problem with create next month if this month at 02/27 with not change to MAR. Anyone have any ideas or different thought on this. Thanks

@echo off
setlocal enabledelayedexpansion

:::::::::::::::::::::::
: Create next Wednesday
:::::::::::::::::::::::

>NextWed.vbs echo Wscript.echo eval(WScript.Arguments(0))
set VBcmd=cscript //nologo NextWed.vbs
set NDW=Wednesday
For /L %%A in (1,1,7) do for /f "delims=" %%N in ('%VBcmd% "weekdayname(weekday(date+%%A))"') do if "%%N"=="%NDW%" set Offset=%%A

for /f "delims=" %%Y in (' %VBcmd% "year(date+%Offset%)" ') do set yyyy=%%Y
for /f "delims=" %%M in (' %VBcmd% "month(date+%Offset%)" ') do set mm=%%M
for /f "delims=" %%D in (' %VBcmd% "day(date+%Offset%)" ') do set dd=%%D

del NextWed.vbs

:::::::::::::::::::::::::::
: Adjust date into 2 digits
:::::::::::::::::::::::::::

if %mm% LSS 10 set mm=0%mm%
if %dd% LSS 10 set dd=0%dd%

:::::::::::::::::::::::::
: Create current Month
:::::::::::::::::::::::::

set Month=%DATE:~4,2%

if %Month_Date%==01 set Month_Date=JAN
if %Month_Date%==02 set Month_Date=FEB
if %Month_Date%==03 set Month_Date=MAR
if %Month_Date%==04 set Month_Date=APR
if %Month_Date%==05 set Month_Date=MAY
if %Month_Date%==06 set Month_Date=JUN
if %Month_Date%==07 set Month_Date=JUL
if %Month_Date%==08 set Month_Date=AUG
if %Month_Date%==09 set Month_Date=SEP
if %Month_Date%==10 set Month_Date=OCT
if %Month_Date%==11 set Month_Date=NOV
if %Month_Date%==12 set Month_Date=DEC

echo %dd%%Month_Date%%date:~10,4%.TEST.TXT > nextwed.txt


So I come up different thought for yr 2013 if fall on those date will change to month need, but don't know how apply in if current month regular or next month.

set Month_Date=%DATE:~4,2%%date:~7,2%

if %Month_Date%==0130 set Month_Date=FEB
if %Month_Date%==0227 set Month_Date=MAR
if %Month_Date%==0327 set Month_Date=APR
if %Month_Date%==0424 set Month_Date=MAY
if %Month_Date%==0529 set Month_Date=JUN
if %Month_Date%==0626 set Month_Date=JUL
if %Month_Date%==0731 set Month_Date=AUG
if %Month_Date%==0828 set Month_Date=SEP
if %Month_Date%==0925 set Month_Date=OCT
if %Month_Date%==1030 set Month_Date=NOV
if %Month_Date%==1127 set Month_Date=DEC
if %Month_Date%==1225 set Month_Date=JAN

echo %dd%%Month_Date%%date:~10,4%.TEST.TXT > nextwed.txt

Is this a exercise or a real-world application?
Real men do not write that kind of code for a trivial problem. There already exists SOLUTIONS for that kind of thing.

But if this is a puzzle, just ignore my comments above.

Noe after having said that....
You can make a table of leap years from data found on the Internet. Wait., I will do lit for you...
Code: [Select]1996
2000 2004 2008 2012 2016 2020 2024 2028 2032 2036 2040 2044 2048
2052 2056 2060 2064 2068 2072 2076 2080 2084 2088 2092 2096 2104

Let me know if you need more... Thank for reply...

Is this a exercise or a real-world application? Yes....this is real-world application.

Real men do not write that kind of code for a trivial problem. There already exists solutions for that kind of thing. Could help me where is the link relate with this?

But if this is a puzzle, just ignore my comments above.

Noe after having said that....
You can make a table of leap years from data found on the Internet. Wait., I will do lit for you...Please....
You can use simple batch arithmetic and some VBS functions.

1. Long

@echo off
echo Wscript.echo eval(WScript.Arguments(0)) > evaluate.vbs
echo wscript.echo DateAdd("d",wscript.arguments(0),date) > futureday.vbs

REM Find the date of next Wednesday or any other day of the week

REM We use these day numbers
REM 1=Sunday 2=Monday 3=Tuesday 4=Wednesday 5=Thursday 6=Friday 7=Saturday

REM 1. Find today's number
REM in VBscript "date" is today's date - ,1 parameter means start week on Sunday
for /f "delims=" %%A in ('cscript //nologo evaluate.vbs "weekday(date,1)"') do set TodayNumber=%%A

echo Today is day number %TodayNumber%

REM Specify which next day to Find
REM Example: Wednesday
set WantedNextDay=4

REM 2. Calculate how many days to wantednextday
set /a DaysToWantedNextDay=%WantedNextDay%-%TodayNumber%
if %DaysToWantedNextDay% LEQ 0 set /a DaysToWantedNextDay+=7

echo Days until next day %WantedNextDay% = %DaysToWantedNextDay%

REM Use VBScript Dateadd to give the date specified days in future
for /f "delims=" %%A in ('cscript //nologo futureday.vbs %DaysToWantedNextDay%') do set NextWantedDayDate=%%A

echo Desired date is %NextWantedDayDate%

2. Short

@echo off
echo Wscript.echo eval(WScript.Arguments(0)) > evaluate.vbs
echo wscript.echo DateAdd("d",wscript.arguments(0),date) > futureday.vbs
for /f "delims=" %%A in ('cscript //nologo evaluate.vbs "weekday(date,1)"') do set TodayNumber=%%A
set WantedNextDay=4
set /a DaysToWantedNextDay=%WantedNextDay%-%TodayNumber%
if %DaysToWantedNextDay% LEQ 0 set /a DaysToWantedNextDay+=7
for /f "delims=" %%A in ('cscript //nologo futureday.vbs %DaysToWantedNextDay%') do set NextWantedDayDate=%%A
echo %NextWantedDayDate%

Example output, format will be your local date format.

Today is day number 2
Days until next day 4 = 2
Desired date is 06/02/2013
















Really nice code, but how we get out put "06MAR2013" And this code will work on every week at Wednesday 12:01 am if run? ThanksThis will give you the next day, 7 days in advance from when it is run, in the format 13Feb2013

Code: [Select]@echo off
echo >"%temp%\%~n0.vbs" s=DateAdd("d",7,now)
echo>>"%temp%\%~n0.vbs" m=MonthName((right(100+month(s),2)), True)
echo>>"%temp%\%~n0.vbs" WScript.Echo right(100+day(s),2) ^& m ^& year(s)

for /f "delims=" %%a in (
'cscript //nologo "%temp%\%~n0.vbs"') do set day=%%a
del "%temp%\%~n0.vbs"

echo %%day%% is set to "%day%" (without the quotes)
pauseI'm not a big fan of these hybrid scripts. It always seemed that anyone with the skills to use batch language to write VBScript code, could write the entire script in VBScript and be DONE with it. On the other HAND when dealing with date or floating point arithmetic they do save jumping thru hoops by using pure batch.

Quote

I so crazy with this batch code for next Wednesday/Month/YR. The code will run every Wednesday 12:01 am will create next Wednesday

This may help:

Code: [Select]@echo off
setlocal

findstr "^:::" "%~sf0" > temp.vbs
for /f %%i in ('cscript //nologo temp.vbs') do echo Next Wednesday is %%i

del temp.vbs
goto :eof

:::WScript.Echo getnextDOW(vbWednesday, Date)

:::Function getNextDOW(intDOW, dtmDate)
::: intTemp = WeekDay(dtmDate)
::: nextDOW = dtmDate - intTemp + intDOW + IIF(intTemp < intDOW, 0, 7)
::: getNextDOW = getLiteralMonth(nextDOW)
:::End Function

:::Function IIF(blnExpression, dhTrue, dhFalse)
::: If blnExpression Then
::: IIF = dhTrue
::: Else IIF = dhFalse
::: End If
:::End Function

:::Function getLiteralMonth(nextDOW)
::: arr = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
::: dtmDay = DatePart("d", nextDOW)
::: if dtmDay < 10 Then dtmDay = "0" & dtmDay
::: getLiteralMonth = dtmDay & arr(DatePart("m", nextDOW) - 1) & DatePart("yyyy", nextDOW)
:::End Function

This will compute the date of any next day of week. Use vbSunday thru vbSaturday to represent the week days in the script at line 10. Note: the IFF function comes straight from VB and prevents flagging the current date as the next DOW.

Onward and Upward .I like this code, but how get out the month with uppercase "12FEB2013". Please help or have different thought. Thanks

Quote
@echo off
echo >"%temp%\%~n0.vbs" s=DateAdd("d",7,now)
echo>>"%temp%\%~n0.vbs" m=MonthName((right(100+month(s),2)), True)
echo>>"%temp%\%~n0.vbs" WScript.Echo right(100+day(s),2) ^& m ^& year(s)

for /f "delims=" %%a in (
'cscript //nologo "%temp%\%~n0.vbs"') do set day=%%a
del "%temp%\%~n0.vbs"

echo %%day%% is set to "%day%" (without the quotes)
pause
Quote from: dtran on February 05, 2013, 09:17:32 AM
I like this code, but how get out the month with uppercase "12FEB2013". Please help or have different thought. Thanks

Make this change

@echo off
echo >"%temp%\%~n0.vbs" s=DateAdd("d",7,now)
echo>>"%temp%\%~n0.vbs" m=MonthName((right(100+month(s),2)), True)
echo>>"%temp%\%~n0.vbs" WScript.Echo right(100+day(s),2) ^& UCASE(m) ^& year(s)

for /f "delims=" %%a in (
'cscript //nologo "%temp%\%~n0.vbs"') do set day=%%a
del "%temp%\%~n0.vbs"

echo %%day%% is set to "%day%" (without the quotes)
pause

Thanks very much guys for help this code work. You guys so good . Finally I have the code below run very Wednesday at 12:01 am and create next Wednesday into a text file then sendevent that text file into gloval variables of Autosy. I just hopefully this 27/02/13 this job will run then create date 06MAR2013.TEL144821D. Thanks

Salmon Trout
foxidrive
Sidewinder
Geek-9pm

Code: [Select]@echo off
echo > "%~n0.vbs" s=DateAdd("d",7,now)
echo >> "%~n0.vbs" m=MonthName((right(100+month(s),2)), True)
echo >> "%~n0.vbs" WScript.Echo right(100+day(s),2) ^& UCASE(m) ^& year(s)

for /f "delims=" %%a in (
'cscript //nologo "%~n0.vbs"') do set nxtWday=%%a
del "%temp%\%~n0.vbs"

echo %nxtWday%.TEL144821D > nxtWday.txt

ping -n 2 127.0.0.1 > nul
for /f %%i in (nxtWday.txt) do sendevent -E SET_GLOBAL -G "FDB_TEL144821D=%%i"


Discussion

No Comment Found