Hi,<\/p>\n
I have a batch file to create a folder with today’s date using %date:~0,2%-%date:~3,2%-%date:~6,4%<\/p>\n
I need a command to detect yesterday’s date but how can this be done?<\/p>\n
I’m thinking something on the lines of:<\/p>\n
IF EXIST c:\\temp%date:~0,2%-%date:~3,2%-%date:~6,4% GOTO yes<\/p>\n
Of course that command detects if a folder with today’s date exists…not yesterdays.<\/p>\n
Thanks<\/p>\n
Chris<\/p>","upvoteCount":4,"answerCount":19,"datePublished":"2012-05-29T00:45:44.000Z","author":{"@type":"Person","name":"chris39668410","url":"https://community.spiceworks.com/u/chris39668410"},"acceptedAnswer":{"@type":"Answer","text":"
Chris<\/p>\n
Batch file as follows, you may need to alter the program flow depending on exactly what you want to do.<\/p>\n
:start<\/strong> :today<\/strong> REM Create yesterday.txt with todays file name to check tomorrow<\/strong> :yes<\/strong> REM jump back to label today to create file etc.<\/strong> Hi,<\/p>\n I have a batch file to create a folder with today’s date using %date:~0,2%-%date:~3,2%-%date:~6,4%<\/p>\n I need a command to detect yesterday’s date but how can this be done?<\/p>\n I’m thinking something on the lines of:<\/p>\n IF EXIST c:\\temp%date:~0,2%-%date:~3,2%-%date:~6,4% GOTO yes<\/p>\n Of course that command detects if a folder with today’s date exists…not yesterdays.<\/p>\n Thanks<\/p>\n Chris<\/p>","upvoteCount":4,"datePublished":"2012-05-29T00:45:44.000Z","url":"https://community.spiceworks.com/t/batch-command-to-detect-yesterdays-date/145698/1","author":{"@type":"Person","name":"chris39668410","url":"https://community.spiceworks.com/u/chris39668410"}},{"@type":"Answer","text":" I’m 99% certain you can’t do that in pure batch file.<\/p>\n I could send you an .EXE file but then I’d be putting you in the position of accepting an executable file from some random guy on the web.<\/p>\n Do you have acces to any compilers ?<\/p>\n I could then ship you the source code which you could verify as safe.<\/p>\n It may be that you should use the at<\/strong> command…<\/p>\n It looks like you have some daily task to execute and you could schedule this using at<\/strong><\/p>\n Edit:<\/strong><\/p>\n if date==29/05/2012 set day=28/05/2012 Thanks Dominic,<\/p>\n Yes it will be a batch file that runs everyday and checks for a filename (sorry, I said folder originally!) with yesterday’s date. If that file exists it uses the GOTO command to then send a specific email via another command<\/p>","upvoteCount":0,"datePublished":"2012-05-29T02:14:17.000Z","url":"https://community.spiceworks.com/t/batch-command-to-detect-yesterdays-date/145698/3","author":{"@type":"Person","name":"chris39668410","url":"https://community.spiceworks.com/u/chris39668410"}},{"@type":"Answer","text":" Apologies if I am being thick here but couldn’t you declare a variable as Date-1 in some way?<\/p>","upvoteCount":0,"datePublished":"2012-05-29T02:47:50.000Z","url":"https://community.spiceworks.com/t/batch-command-to-detect-yesterdays-date/145698/4","author":{"@type":"Person","name":"Briser-fae-the-broch","url":"https://community.spiceworks.com/u/Briser-fae-the-broch"}},{"@type":"Answer","text":" Yes, I was thinking that…but I’m not 100% on the usage of the code. Then I thought, if it’s 01-01-2012 yesterday’s date would be 30-04-2012 so the DAY, MONTH and YEAR would need to be checked as all three would change to a previous day, month, year.<\/p>","upvoteCount":0,"datePublished":"2012-05-29T02:53:16.000Z","url":"https://community.spiceworks.com/t/batch-command-to-detect-yesterdays-date/145698/5","author":{"@type":"Person","name":"chris39668410","url":"https://community.spiceworks.com/u/chris39668410"}},{"@type":"Answer","text":" I can send you the spreadsheet that generated that ugly solution.<\/p>","upvoteCount":0,"datePublished":"2012-05-29T02:55:15.000Z","url":"https://community.spiceworks.com/t/batch-command-to-detect-yesterdays-date/145698/6","author":{"@type":"Person","name":"dominicconnor0895","url":"https://community.spiceworks.com/u/dominicconnor0895"}},{"@type":"Answer","text":" Thanks!<\/p>\n It’ll get virus checked so don’t worry about a secure risk Thanks<\/p>\n Chris<\/p>","upvoteCount":0,"datePublished":"2012-05-29T02:57:00.000Z","url":"https://community.spiceworks.com/t/batch-command-to-detect-yesterdays-date/145698/7","author":{"@type":"Person","name":"chris39668410","url":"https://community.spiceworks.com/u/chris39668410"}},{"@type":"Answer","text":" As you are running this everyday, then when you create the file for today why not also pipe the current date to yesterday.txt then when you need the date tommorrow you can pult it with a for command similar to below<\/p>\n for /f %%y in (yesterday.txt) do if exist %%y goto yes<\/p>","upvoteCount":0,"datePublished":"2012-05-29T03:00:52.000Z","url":"https://community.spiceworks.com/t/batch-command-to-detect-yesterdays-date/145698/8","author":{"@type":"Person","name":"rossbaines","url":"https://community.spiceworks.com/u/rossbaines"}},{"@type":"Answer","text":" the forfiles command may also do what you need but that works on the files modified date rather then the filename.<\/p>\n see Forfiles - Batch process multiple files - Windows CMD - SS64.com<\/a><\/p>","upvoteCount":0,"datePublished":"2012-05-29T03:02:49.000Z","url":"https://community.spiceworks.com/t/batch-command-to-detect-yesterdays-date/145698/9","author":{"@type":"Person","name":"rossbaines","url":"https://community.spiceworks.com/u/rossbaines"}},{"@type":"Answer","text":" Seems sensible Ross!<\/p>\n How do you ‘pipe’ to a .txt file?<\/p>","upvoteCount":0,"datePublished":"2012-05-29T03:19:21.000Z","url":"https://community.spiceworks.com/t/batch-command-to-detect-yesterdays-date/145698/10","author":{"@type":"Person","name":"chris39668410","url":"https://community.spiceworks.com/u/chris39668410"}},{"@type":"Answer","text":" echo %date:~0,2%-%date:~3,2%-%date:~6,4% > yesterday.txt<\/p>\n the single ‘>’ will overwrite the contents<\/p>","upvoteCount":0,"datePublished":"2012-05-29T03:26:30.000Z","url":"https://community.spiceworks.com/t/batch-command-to-detect-yesterdays-date/145698/11","author":{"@type":"Person","name":"rossbaines","url":"https://community.spiceworks.com/u/rossbaines"}},{"@type":"Answer","text":" Hi Ross,<\/p>\n That works for me. I’m trying to understand your original post though:<\/p>\n for /f %%y in (yesterday.txt) do if exist %%y goto yes<\/p>\n So, I’d need to check for c:\\temp\\29-05-2012.zip and if that files exists GOTO the line :yes<\/p>\n How would your code look?<\/p>\n Thanks<\/p>\n chris<\/p>","upvoteCount":0,"datePublished":"2012-05-29T04:15:08.000Z","url":"https://community.spiceworks.com/t/batch-command-to-detect-yesterdays-date/145698/12","author":{"@type":"Person","name":"chris39668410","url":"https://community.spiceworks.com/u/chris39668410"}},{"@type":"Answer","text":" Incidentally I’ve manipulated your other post as:<\/p>\n echo %date:~0,2%-%date:~3,2%-%date:~6,4%.zip > c:\\yesterday.txt<\/p>","upvoteCount":0,"datePublished":"2012-05-29T04:29:29.000Z","url":"https://community.spiceworks.com/t/batch-command-to-detect-yesterdays-date/145698/13","author":{"@type":"Person","name":"chris39668410","url":"https://community.spiceworks.com/u/chris39668410"}},{"@type":"Answer","text":" Chris3966 wrote:<\/p>\n Yes, I was thinking that…but I’m not 100% on the usage of the code. Then I thought, if it’s 01-01-2012 yesterday’s date would be 30-04-2012 so the DAY, MONTH and YEAR would need to be checked as all three would change to a previous day, month, year.<\/p>\n<\/blockquote>\n Ah, good point - although perhaps there is a smart way to rewind a single day from the Date variable but if there is, I wouldn’t know.<\/p>\n I like Ross’s idea of piping todays date into a file “Yesterday” and using it tomorrow, kinda reminds me of the lines in a Marillion song called Ricochet - “Yesterday starts tomorrow, tomorrow starts today”!<\/p>","upvoteCount":0,"datePublished":"2012-05-29T05:37:41.000Z","url":"https://community.spiceworks.com/t/batch-command-to-detect-yesterdays-date/145698/15","author":{"@type":"Person","name":"Briser-fae-the-broch","url":"https://community.spiceworks.com/u/Briser-fae-the-broch"}},{"@type":"Answer","text":" Hi Mate<\/p>\n
\nREM Do the check on yesterdays file<\/strong>
\nREM reads the content of yesterday.txt and store it in varible &&y<\/strong>
\nREM checks for the file named %%y and if it exists jump to lable :yes<\/strong>
\nfor /f %%y in (yesterday.txt) do if exist %%y goto yes<\/strong><\/p>\n
\nREM Create todays file<\/strong>
\ncommands for whatever it is you want to do here that creates %date:~0,2%-%date:~3,2%-%date:~6,4%.zip<\/em><\/strong><\/p>\n
\necho %date:~0,2%-%date:~3,2%-%date:~6,4%.zip > yesterday.txt<\/strong>
\n:goto end<\/strong><\/p>\n
\ncommands for whatever it is you want to do here on yesterdays file<\/em><\/strong><\/p>\n
\ngoto today<\/strong>
\n:end<\/strong><\/p>","upvoteCount":0,"datePublished":"2012-05-29T04:42:13.000Z","url":"https://community.spiceworks.com/t/batch-command-to-detect-yesterdays-date/145698/14","author":{"@type":"Person","name":"rossbaines","url":"https://community.spiceworks.com/u/rossbaines"}},"suggestedAnswer":[{"@type":"Answer","text":"
\nif date==30/05/2012 set day=29/05/2012
\nif date==31/05/2012 set day=30/05/2012
\nif date==01/06/2012 set day=31/05/2012
\nif date==02/06/2012 set day=01/06/2012
\nif date==03/06/2012 set day=02/06/2012
\nif date==04/06/2012 set day=03/06/2012
\nif date==05/06/2012 set day=04/06/2012
\nif date==06/06/2012 set day=05/06/2012
\nif date==07/06/2012 set day=06/06/2012
\nif date==08/06/2012 set day=07/06/2012
\nif date==09/06/2012 set day=08/06/2012
\nif date==10/06/2012 set day=09/06/2012
\nif date==11/06/2012 set day=10/06/2012
\nif date==12/06/2012 set day=11/06/2012
\nif date==13/06/2012 set day=12/06/2012
\nif date==14/06/2012 set day=13/06/2012
\nif date==15/06/2012 set day=14/06/2012
\nif date==16/06/2012 set day=15/06/2012
\nif date==17/06/2012 set day=16/06/2012
\nif date==18/06/2012 set day=17/06/2012
\nif date==19/06/2012 set day=18/06/2012
\nif date==20/06/2012 set day=19/06/2012
\nif date==21/06/2012 set day=20/06/2012
\nif date==22/06/2012 set day=21/06/2012
\nif date==23/06/2012 set day=22/06/2012
\nif date==24/06/2012 set day=23/06/2012
\nif date==25/06/2012 set day=24/06/2012
\nif date==26/06/2012 set day=25/06/2012
\nif date==27/06/2012 set day=26/06/2012
\nif date==28/06/2012 set day=27/06/2012
\nif date==29/06/2012 set day=28/06/2012
\nif date==30/06/2012 set day=29/06/2012
\nif date==01/07/2012 set day=30/06/2012
\nif date==02/07/2012 set day=01/07/2012
\nif date==03/07/2012 set day=02/07/2012
\nif date==04/07/2012 set day=03/07/2012
\nif date==05/07/2012 set day=04/07/2012
\nif date==06/07/2012 set day=05/07/2012
\nif date==07/07/2012 set day=06/07/2012
\nif date==08/07/2012 set day=07/07/2012
\nif date==09/07/2012 set day=08/07/2012
\nif date==10/07/2012 set day=09/07/2012
\nif date==11/07/2012 set day=10/07/2012
\nif date==12/07/2012 set day=11/07/2012
\nif date==13/07/2012 set day=12/07/2012
\nif date==14/07/2012 set day=13/07/2012
\nif date==15/07/2012 set day=14/07/2012
\nif date==16/07/2012 set day=15/07/2012
\nif date==17/07/2012 set day=16/07/2012
\nif date==18/07/2012 set day=17/07/2012
\nif date==19/07/2012 set day=18/07/2012
\nif date==20/07/2012 set day=19/07/2012
\nif date==21/07/2012 set day=20/07/2012
\nif date==22/07/2012 set day=21/07/2012
\nif date==23/07/2012 set day=22/07/2012
\nif date==24/07/2012 set day=23/07/2012
\nif date==25/07/2012 set day=24/07/2012
\nif date==26/07/2012 set day=25/07/2012
\nif date==27/07/2012 set day=26/07/2012<\/p>","upvoteCount":0,"datePublished":"2012-05-29T02:05:51.000Z","url":"https://community.spiceworks.com/t/batch-command-to-detect-yesterdays-date/145698/2","author":{"@type":"Person","name":"dominicconnor0895","url":"https://community.spiceworks.com/u/dominicconnor0895"}},{"@type":"Answer","text":"<\/p>\n
\n