August 20th, 2012, 01:39 PM
DOS-Batch file find date for last weeks Monday
How do I find the date for last weeks Monday in a DOS batch file?
I would like to pull it into the following format 'yyyy-mm-dd' and assign it to a variable to use as part of a file name later on in the program.
Any help on this would be greatly appreciated, thanks in advance!
September 10th, 2012, 04:10 PM
Does anyone know DOS well enough to know if this is possible?
December 24th, 2012, 05:24 AM
Dos batch may not be powerful enough
Check this out to see an elaborate date manipulation system for dos.
Given its complexity, It may be time to give up on dos and move to a more powerful scripting language.
I had done that back in the early 90s and switched to perl for all "batch" work. Today Strawberry perl is a version of perl that included lots of windows specific functionality.
The transition is not hard because. At first all you do is run perl to set variables to values you can't do in dos alone. As you get stronger in it you do more because it's less code and easier.
If you are required to work with Microsoft specific product the alternative is PowerShell. Its run on XP and more recent versions of window. It's MS's official replacement for dos batch files.
I am on vacation this week but I have allocated some recreation hacking time into the day so I may be able to put some scripts together.
Last edited by admiraln; December 24th, 2012 at 05:37 AM.
Reason: Fix title
December 29th, 2012, 11:42 PM
I've actually been able to do this with some vb script and DOS...
Example I create a "CreateSQL.vbs" file with notepad
and then I call it with a DOS .bat file like
' Wscript.Echo DateAdd("d",-1,Now)
LMon = DateAdd("d",(WeekDay(Date())-2)*-1,Date())
dim filesys, filetxt, getname, path
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.CreateTextFile("F:\PathToSQL\CreatePDTable.sql", True)
path = filesys.GetAbsolutePathName("F:\PathToSQL\CreatePDTable.sql")
getname = filesys.GetFileName(path)
filetxt.WriteLine("DROP TABLE IF EXISTS PARTDATA.TBLPD" & Year(LMon) & Right("0" & Month(LMon),2) & Right("0" & Day(LMon),2) & ";")
filetxt.WriteLine("CREATE TABLE PARTDATA.TBLPD" & Year(LMon) & Right("0" & Month(LMon),2) & Right("0" & Day(LMon),2))
and then in the DOS .bat file I call the .sql file that's created like:
C:\xampp\mysql\bin\mysql -u root -password -D databasename < "F:\PathToSQL\CreatePDTable.sql"