Computer Hope

Microsoft => Microsoft DOS => Topic started by: Zensar on July 29, 2010, 06:48:54 AM

Title: how to get next saturday 'Date' in DOS batch file
Post 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.
Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: southpaw63119 on July 29, 2010, 10:49:19 AM
This may help you get started:
http://www.computerhope.com/forum/index.php?topic=76081.0
Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: Salmon Trout on July 29, 2010, 11:39:41 AM
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.

Code: [Select]
@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%

Code: [Select]
Next Saturday Is 31/07/2010


Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: Zensar on July 29, 2010, 02:28:45 PM
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
Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: Salmon Trout on July 29, 2010, 02:51:45 PM
convert the output date format from dd/mm/yyyy to yyyymmdd'

assuming %NextSaturday% is dd/mm/yyyy

Code: [Select]
set yyyy=%NextSaturday:~6,4%
set mm=%NextSaturday:~3,2%
set dd=%NextSaturday:~0,2%
set yourformat=%yyyy%%mm%%dd%
echo %yourformat%
Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: Zensar on July 30, 2010, 12:02:48 AM
Hi Salmon,
Code: [Select]
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.
Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: Salmon Trout on July 30, 2010, 12:09:30 AM
Did you read this?

Quote from: Me
assuming %NextSaturday% is dd/mm/yyyy

I tested it before posting. It works fine here.



Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: Zensar on July 30, 2010, 02:15:24 AM
Hi Salmon,
I am using your code in the below mentioned manner
Code: [Select]
@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

Code: [Select]
Next Saturday Is 7/31/2010
yourformat /210

Please help.
Thanks in advance
Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: Salmon Trout on July 30, 2010, 03:11:01 AM
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.
Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: Zensar on July 30, 2010, 03:28:08 AM
ohhhhhhh yes I overlooked the date format.
do you know a workaround for converting 'm/d/yyyy' to 'yyyymmdd'

Thanks in advance.
Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: Salmon Trout on July 30, 2010, 10:58:39 AM
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.

Code: [Select]
@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

Code: [Select]
Next Saturday is 20100731



Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: Salmon Trout on July 31, 2010, 02:02:43 AM
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.

Code: [Select]
@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


Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: Zensar on August 13, 2010, 01:50:55 AM
Thanks a lot  Salmon!!!
You ROCK!!!!!! (|
Issue resolved.
Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: vishuvishal on August 13, 2010, 05:25:31 PM
Code: [Select]
@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
Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: vishuvishal on August 13, 2010, 05:32:03 PM
Hey Salmon.
You are getting help from VBscript or windows script.

Is it fair?

Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: BC_Programmer on August 13, 2010, 10:58:02 PM
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.
Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: Salmon Trout on August 14, 2010, 12:52:06 AM
Hey Salmon.
You are getting help from VBscript or windows script.

Is it fair?



Please restrict yourself to on-topic, useful posts.
Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: Salmon Trout on August 14, 2010, 01:09:28 AM

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.
Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: ghostdog74 on August 14, 2010, 07:30:23 PM
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?
Title: Re: how to get next saturday \\\'Date\\\' in DOS batch file
Post by: victoria on August 14, 2010, 08:25:41 PM
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.




Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: BC_Programmer on August 14, 2010, 08:26:34 PM
LOL, well, if we needed a post to confirm our suspicions, that would be it.
Title: How to get next saturday \'Date\' in DOS batch file
Post by: victoria on August 14, 2010, 08:32:49 PM
Well, if we needed a post to confirm our suspicions, that would be it.

Say What?

Are we Off Topic?
Title: Re: how to get next saturday \\\'Date\\\' in DOS batch file
Post by: Salmon Trout on August 15, 2010, 01:12:09 AM

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.


 :)
Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: vishuvishal on August 15, 2010, 06:41:43 PM
Thank you Victoria.
Pure soul!
Pure hear!
Not flirting
Truth is truth
he he he...
 ;D ;D ;D ;D ;D ;D
Title: How to get next saturday Date in DOS batch file
Post by: RoyBailey on August 16, 2010, 08:08:14 PM


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>
Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: Salmon Trout on August 16, 2010, 11:56:34 PM
So, "RoyBailey", will that script work anywhere in the world?

http://i7.photobucket.com/albums/y268/billrich/aug.jpg
Title: How to get next saturday Date in DOS batch file
Post by: RoyBailey on August 17, 2010, 09:34:48 AM
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.
Title: Re: How to get next saturday Date in DOS batch file
Post by: Salmon Trout on August 17, 2010, 10:32:10 AM
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?)

Quote
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.
Title: How to get next saturday Date in DOS batch file
Post by: RoyBailey on August 17, 2010, 11:40:25 AM
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.
Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: Salmon Trout on August 17, 2010, 12:32:48 PM
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:


Quote
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.


Title: Re: how to get next saturday Date in DOS batch file
Post by: RoyBailey on August 17, 2010, 12:57:45 PM
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.
Title: Re: how to get next saturday \'Date\' in DOS batch file
Post by: Salmon Trout on August 17, 2010, 01:07:43 PM

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.
Title: How to get next saturday Date in DOS batch file
Post by: RoyBailey on August 17, 2010, 03:23:08 PM
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>
Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: Salmon Trout on August 17, 2010, 03:31:42 PM
(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.






Title: How to get next saturday Date in DOS batch file
Post by: RoyBailey on August 17, 2010, 03:58:17 PM
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
Title: Re: How to get next saturday Date in DOS batch file
Post by: BC_Programmer on August 17, 2010, 04:52:52 PM
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".

Quote
His code works well.
Yes. It already works.

Quote
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.

Quote
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)
Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: kpac on August 17, 2010, 04:58:47 PM
Bill, wherever you got your "BS.c", I'm not going there.
Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: BC_Programmer on August 17, 2010, 05:25:23 PM
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.
Title: Re: How to get next saturday Date in DOS batch file
Post by: Salmon Trout on August 17, 2010, 11:59:09 PM

The ComputerHope member who is so upset has worked on his Saturday Code for years.


About 10 minutes actually.
Title: Re: how to get next saturday Date in DOS batch file
Post by: Fields on August 23, 2010, 06:08:08 PM

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?
Title: How to get next saturday Date in DOS batch file
Post by: Fields on August 23, 2010, 09:40:41 PM
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:\\\\>
Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: Salmon Trout on August 23, 2010, 11:51:18 PM
Hello again, Bill. In Bill's world, you can get an edited version of my vbs script from a "Unix board".


Title: How to get next saturday Date in DOS batch file
Post by: Fields on August 24, 2010, 09:13:52 AM
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.
Title: Re: How to get next saturday Date in DOS batch file
Post by: BC_Programmer on August 24, 2010, 09:30:56 AM
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.
Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: Salmon Trout on August 24, 2010, 09:39:08 AM
BCP, I think we just fed the troll.
Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: BC_Programmer on August 24, 2010, 09:40:27 AM
True, but I wanted to see how my insult generator worked.
Title: How to get next saturday Date in DOS batch file
Post by: Fields on August 24, 2010, 11:55:16 AM
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.
Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: gpl on August 24, 2010, 12:07:07 PM
True, but I wanted to see how my insult generator worked.
Plz send me codez 4dis ;D
Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: kpac on August 24, 2010, 12:25:04 PM
Code: [Select]
<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>
Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: gpl on August 24, 2010, 02:16:01 PM
Cheers :)
Title: How to get next saturday Date in DOS batch file
Post by: Fields on August 24, 2010, 02:32:05 PM


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>
Title: Re: how to get next saturday 'Date' in DOS batch file
Post by: Allan on August 24, 2010, 03:18:52 PM
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.