Computer Hope
Microsoft => Microsoft DOS => Topic started by: Zensar on July 29, 2010, 06:48:54 AM
-
I have a dos batch file which processes a text file and generates a .csv output file. I want to append the next Saturday date to the output file name.
Right now I am able to append the current date by using the below mentioned logic
Code:
set Pdate=%date:~10,4%%date:~4,2%%date:~7,2% {setting current date to variable}
-outputFile %OUTDIR%\AglItemMaster_"%PDATE%".csv
now I want to pass next saturday date in place of current date.
Kindly help.
A quick response will be really helpful.
-
This may help you get started:
http://www.computerhope.com/forum/index.php?topic=76081.0
-
I am (or was) Dias de verano.
Output should be next Saturday's date in your local date format. Mine is European dd/mm/yyyy.
@echo off
>NextSat.vbs echo wscript.echo FormatDateTime(Date + (7 - Weekday(Date)))
For /f "delims=" %%D in ('cscript //nologo NextSat.vbs') do set nextsaturday=%%D
del NextSat.vbs
echo Next Saturday Is %Nextsaturday%
Next Saturday Is 31/07/2010
-
Thanks a ton Salmon for resolving my issue.
Just a quick one 'how do I convert the output date format from dd/mm/yyyy to yyyymmdd'
Thanks in advance
-
convert the output date format from dd/mm/yyyy to yyyymmdd'
assuming %NextSaturday% is dd/mm/yyyy
set yyyy=%NextSaturday:~6,4%
set mm=%NextSaturday:~3,2%
set dd=%NextSaturday:~0,2%
set yourformat=%yyyy%%mm%%dd%
echo %yourformat%
-
Hi Salmon,
set yyyy=%NextSaturday:~6,4%
set mm=%NextSaturday:~3,2%
set dd=%NextSaturday:~0,2%
set yourformat=%yyyy%%mm%%dd%
echo yourformat %yourformat%
this is not working.
-
Did you read this?
assuming %NextSaturday% is dd/mm/yyyy
I tested it before posting. It works fine here.
-
Hi Salmon,
I am using your code in the below mentioned manner
@echo off
>NextSat.vbs echo wscript.echo FormatDateTime(Date + (7 - Weekday(Date)))
For /f "delims=" %%D in ('cscript //nologo NextSat.vbs') do set nextsaturday=%%D
del NextSat.vbs
set yyyy=%NextSaturday:~10,4%
set mm=%NextSaturday:~4,2%
set dd=%NextSaturday:~7,2%
set yourformat=%yyyy%%mm%%dd%
echo Next Saturday Is %Nextsaturday%
echo yourformat %yourformat%
And getting the output as
Next Saturday Is 7/31/2010
yourformat /210
Please help.
Thanks in advance
-
you wrongly gave your date format as dd/mm/yyyy when it appears to actually be m/d/yyyy, which is why the code I supplied does not give the result you require.
-
ohhhhhhh yes I overlooked the date format.
do you know a workaround for converting 'm/d/yyyy' to 'yyyymmdd'
Thanks in advance.
-
This will place into a batch variable the following Saturday's date in yyyymmdd format. That is, 4 figures for the year and 2 figures each for month and day, (example 20100731) whatever the local date format.
@echo off
>NextSat.vbs echo NextSaturday=FormatDateTime(Date+(7-Weekday(Date)))
>>NextSat.vbs echo SY=Year(NextSaturday)
>>NextSat.vbs echo SM=Month(NextSaturday)
>>NextSat.vbs echo SD=Day(NextSaturday)
>>NextSat.vbs echo wscript.echo SY ^& "," ^& SM ^& "," ^& SD
For /f "tokens=1-3 delims=," %%A in ('cscript //nologo NextSat.vbs') do (
Set yyyy=%%A
Set mm=%%B
Set dd=%%C
)
del Nextsat.vbs
If %mm% lss 10 Set mm=0%mm%
If %dd% lss 10 Set dd=0%dd%
Set Result=%yyyy%%mm%%dd%
echo Next Saturday is %Result%
pause
Next Saturday is 20100731
-
The previous code had a possible problem, namely that if today is Saturday, it gives today's date. If you do not want that to happen, the following avoids that, and can be adjusted for any day of the week.
@echo off
setlocal enabledelayedexpansion
>evaluate.vbs echo Wscript.echo eval(WScript.Arguments(0))
set VBcmd=cscript //nologo evaluate.vbs
set NDW=Saturday
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
if %mm% LSS 10 set mm=0%mm%
if %dd% LSS 10 set dd=0%dd%
del evaluate.vbs
echo Next %NDW% is %yyyy%%mm%%dd%
pause
-
Thanks a lot Salmon!!!
You ROCK!!!!!! (|
Issue resolved.
-
@echo off
>NextSat.vbs echo wscript.echo FormatDateTime(Date + (7 - Weekday(Date)))
For /f "delims=" %%D in ('cscript //nologo NextSat.vbs') do set nextsaturday=%%D
echo Next Saturday Is %Nextsaturday%
set yyyy=%NextSaturday:~5,4%
set mm=%NextSaturday:~2,2%
set dd=%NextSaturday:~0,1%
set yourformat=%yyyy%/%mm%/%dd%
echo %yourformat%
Hey I got correction.
Thanks and regards
vishu
-
Hey Salmon.
You are getting help from VBscript or windows script.
Is it fair?
-
Hey Salmon.
You are getting help from VBscript or windows script.
Is it fair?
Curious. This post and it's thinly veiled passive sentence form reinforce my suspicions.
-
Hey Salmon.
You are getting help from VBscript or windows script.
Is it fair?
Please restrict yourself to on-topic, useful posts.
-
Curious. This post and it's thinly veiled passive sentence form reinforce my suspicions.
I have had the same suspicions myself. When the axe falls it should remove at least two heads.
-
Hey Salmon.
You are getting help from VBscript or windows script.
Is it fair?
i don't know the details, but why is it not fair ? vbscript or other decent languages that knows how to calculate dates like that does the job. There is no prize for using only batch. Nobody is going to give you money using only batch. Are you greg/bill?
-
Are youl?
The people using more than one current login would have the same
IP address. The Computerhope staff has access to the IP addresses.
Why the undue concern?
I have seen no damage by Vishuvishal.
There appears to be an Inhouse Computerhope Bully Squad.
Victoria and Vishuvishal are not the same person.
Only Victoria and Vishuvishal have been logged on at the same time.
Their IP address for Victoria and Vishuvishal indicates they are not the same person.
-
LOL, well, if we needed a post to confirm our suspicions, that would be it.
-
Well, if we needed a post to confirm our suspicions, that would be it.
Say What?
Are we Off Topic?
-
Only Victoria and Vishuvishal have been logged on at the same time.
Their IP address for Victoria and Vishuvishal indicates they are not the same person.
:)
-
Thank you Victoria.
Pure soul!
Pure hear!
Not flirting
Truth is truth
he he he...
;D ;D ;D ;D ;D ;D
-
set Pdate=%date:~10,4%%date:~4,2%%date:~7,2%
C:test>type sat.bat
@echo off
SET /a SatDate=%DATE:~7,2% +%1
echo SatDate=%SatDate%
Output:
C:test>sat.bat 5
SatDate=21
C:test>
(http://i7.photobucket.com/albums/y268/billrich/aug.jpg)
___________________________________
C:test>type sat.bat
@echo off
SET /A SatDate=%DATE:~7,2% +%1
echo SatDate=%SatDate%
set Pdate=%date:~10,4%%date:~4,2%%SatDate%
echo Pdate=%Pdate%
C:test>
Output:
C:test>sat.bat 5
SatDate=21
Pdate=20100821
C:test>
-
So, "RoyBailey", will that script work anywhere in the world?
http://i7.photobucket.com/albums/y268/billrich/aug.jpg
-
So, RoyBailey, will that script work anywhere in the world?
aug.jpg
ST,
My solution for finding next Saturday is with batch. ST does not use batch.
The Original Poster will decide which method works best for his use.
The readers will make the same choice
My solution will work anywhere in the world with slight and easy modification.
One line of code instead of several lines.
-
My solution for finding next Saturday is with batch.
But it doesn't find the following Saturday, unless you tell it how many days there are until next Saturday! (Is this guy for real?)
ST does not use batch.
THis is false as well.
RoyBailey is actually Billrich, the banned troll. Banned for repeatedly posting misleading, wrong and false "solutions" and abusing forum members. And for evading the ban by rejoining using a proxy server.
-
But it doesnt find the following Saturday, unless you tell it how many days there are until next Saturday.
ST,
Your Staturday solution is great.
The Original Poster and the readers will decide what works best for them.
It is good the Original Poster and the readers have a choice.
Have a good day and thanks for the kind words.
-
RoyBailey, you are one of the most unpleasantly stupid imbeciles it has ever been my misfortune to encounter. I see you shirk any discussion of your "code". The OP has a "choice" between: code that works and your lunatic nonsense, which you posted a long while after this very touching message:
Thanks a lot Salmon!!!
You ROCK!!!!!! Ban-cha
Issue resolved.
I fear that ComputerHope's effectiveness will be gravely compromised until some method of permanently banning Billrich is found.
-
RoyBailey, you are one of the most astonishingly stupid imbeciles it has ever been my misfortune to encounter. I see you shirk any discussion of your code. The OP has a choice between: code that works and your lunatic nonsense, which you posted a long while after this very touching message.
I fear that ComputerHopes effectiveness will be gravely compromised until some method of permanently banning is found.
ST,
Thanks for the kind words.
Some computerhope members would resort to vicious personal attacks.
The people who use the Computerhope Board can filter the good code from the bad.
A member who acts as the Final Judge is not needed.
-
The people who use the Computerhope Board can filter the good code from the bad.
They shouldn't have to filter code that works from deliberately posted trolling nonsense.
-
Right now I am able to append the current date by using the below mentioned logic.
set Pdate=%date:~10,4%%date:~4,2%%date:~7,2%
Now I want to pass next saturday date in place of current date.
( The following code requires no command line arguments or user input. )
C:test>type sat3.bat
@echo off
set day=%DATE:~0,3%
echo day=%day%
if %day%==Sun (
set /a num=6
goto adjust
)
if %day%==Mon (
set /a num=5
goto adjust
)
if %day%==Tue (
set /a num=4
goto adjust
)
if %day%==Wed (
set /a num=3
goto adjust
)
if %day%==Thu (
set /a num=2
goto adjust
)
if %day%==Fri set /a num=1
:adjust
set /a SatDate=%DATE:~7,2% +%num%
echo SatDate=%SatDate%
set Pdate=%date:~10,4%%date:~4,2%%SatDate%
echo Pdate=%Pdate%
Output:
C:test>sat3.bat
day=Tue
SatDate=21
Pdate=20100821
C:test>
-
(1) echo %date%
17/08/2010
No "Tue" around here. So your code breaks. But even in Yankee land...
(2) Run the code on the 8th or 9th of the month, it'll crash. (You won't understand why)
(3) Two weeks from today, your code will say that "next Saturday" is August 35th. Nice code, genius! They must be so inbred in your trailer park that the month of August doesn't stop at 31 like it does everywhere else.
Way past time this dimbulb was banned again.
-
Right now I am able to append the current date by using the below mentioned logic
set Pdate=%date:~10,4%%date:~4,2%%date:~7,2% {
Now I want to pass next saturday date in place of current date.
Zensar,
The ComputerHope member who is so upset has worked on his Saturday Code for years.
His code works well.
I have only worked on the Saturday Code for a day or two. My code has a few bugs that can be worked
out.
My code is strickly batch and in the end will work better.
Roy
-
The ComputerHope member who is so upset has worked on his Saturday Code for years.
I'm not even going to say "I doubt it" Or "probably not" and I'm just going say "that's utter nonsense".
His code works well.
Yes. It already works.
I have only worked on the Saturday Code for a day or two. My code has a few bugs that can be worked
out.
I doubt you will figure out what they are. And even if you do, the best case scenario is you will have a locale specific implementation. It will never work anywhere the regional settings don't match yours. But of course only terrorists would dare to vary from the MM/DD/YY format. In fact one might even suppose that the entire concept of different date formats was established in order to circumvent your code working in the future. Clearly a evil terrorist cell has gone back in time and established these silly conventions like DD/MM/YY, because clearly no sane person would ever order the values in increasing order of their magnitude. Nope, it makes far more sense to use the completely abstract MM/DD/YY ordering. Otherwise UPS wins.
My code is strickly batch and in the end will work better.
Why? How do you know this? As I noted it will not work outside North America, and in fact won't even work in some places there (some people are clearly supporting terrorist groups since they use the DD/MM/YY format)
-
Bill, wherever you got your "BS.c", I'm not going there.
-
Bill, wherever you got your "BS.c", I'm not going there.
It was the early 50's. They were different times.
In some classes the, professor was simply a bear wearing glasses. He didn't like when people would be talking on their lapphones.
-
The ComputerHope member who is so upset has worked on his Saturday Code for years.
About 10 minutes actually.
-
Right now I am able to append the current date by using the below mentioned logic
Code:
set Pdate=%date:~10,4%%date:~4,2%%date:~7,2%
Now I want to pass next saturday date in place of current date.
http://www.unix.com/windows-dos-issues-discussions/140891-how-get-next-saturdays-date.html
#1 4 Weeks Ago
Zensar
Registered User
Join Date: Jul 2010
How to get next Saturdays Date?
--------------------------------------------------------------------------------
( Answer from Unix Board)
@echo off
>#.vbs echo wsh.echo Set Nextsaturday=^&dateAdd(d,7-Weekday(Date),date)
for /f delims= %%_ in (cscript /nologo #.vbs) do %%_
del #.vbs
set Nextsaturday
_______________________________________ ___
Does the above work when next saturday is next month and/or next year?
-
http://www.unix.com/windows-dos-issues-discussions/140891-how-get-next-saturdays-date.html
Does the above work when next saturday is next month?
The VBS code works when saturday is in the next month.
Current Date is changed from Current date to Current date + 7 for test.
Code:
@echo off
For /f delims= %%D in (cscript //nologo NextSat.vbs) do (
set nextsaturday=%%D
)
set nextsaturday=%nextsaturday:~0,8%
echo Next Saturday Is %Nextsaturday%
echo When Current date + 7
Output:
C:> nix.bat
Next Saturday Is 9/4/2010
When Current date + 7
C:>type NextSat.vbs
CurrentDate=now +7
wscript.echo FormatDateTime(CurrentDate + (7 - Weekday(CurrentDate)))
C:>
Q.E.D
C:>echo %DATE%
Mon 08/23/2010
C:>echo %TIME%
23:21:39.15
C:\\\\>
-
Hello again, Bill. In Bill's world, you can get an edited version of my vbs script from a "Unix board".
-
You can get an edited version of my vbs script from a Unix board.
VBS Script does not belong to Salmon Trout.
VBS Script is owned by Microsoft.
-
VBS Script does not belong to Salmon Trout.
VBS Script is owned by Microsoft.
The script itself, you incontinent turkey faced badger-legged Chinchilla loving Carnal Ostrich visitor, not the interpreter.
-
BCP, I think we just fed the troll.
-
True, but I wanted to see how my insult generator worked.
-
True, but I wanted to see how my insult generator worked.
Such beautiful, kind posts are good advertisement to all vistors to the Computerhope site.
Your PR rating is excellent.
-
True, but I wanted to see how my insult generator worked.
Plz send me codez 4dis ;D
-
<a href="http://www.google.com/#hl=en&source=hp&q=insult+generator&aq=0p&aqi=g-p1g9&aql=&oq=insult+&gs_rfai=&fp=93c3c78db929eee0">Click me!</a>
-
Cheers :)
-
set Pdate=%date:~10,4%%date:~4,2%%date:~7,2%
Now I want to pass next saturday date in place of current date.
The following VBS/Batch finds Saturday date when Saturday is next month. Current date is current date + 7( ran 8/23/2010). A for loop is not necessary.
@echo off
cscript //nologo sattwo.vbs > cdate.txt
type cdate.txt
set /p nextsaturday=<cdate.txt
set nextsaturday=%nextsaturday:~0,8%
echo Next Saturday Is %Nextsaturday%
echo When Current date + 7
Output:
C:test> nix2.bat
9/4/2010 3:25:49 PM
Next Saturday Is 9/4/2010
When Current date + 7
C:test>type sattwo.vbs
CurrentDate=now +7
wscript.echo FormatDateTime(CurrentDate + (7 - Weekday(CurrentDate)))
C:test>
-
Okay, I'm going to assume zensar's question has been answered. If not zensar, please send me a PM. But for now, this thread is locked.