#1
  1. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2003
    Posts
    1,003
    Rep Power
    32

    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!
  2. #2
  3. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2003
    Posts
    1,003
    Rep Power
    32
    Does anyone know DOS well enough to know if this is possible?
  4. #3
  5. No Profile Picture
    Still Learning
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Location
    Montreal, Canada
    Posts
    55
    Rep Power
    40

    Dos batch may not be powerful enough


    Check this out to see an elaborate date manipulation system for dos.

    https://groups.google.com/forum/m/?hl=en&fromgroups#!msg/alt.msdos.batch.nt/nPqF9_sT6Wc/ZxXoy7SfzuAJ

    Given its complexity, It may be time to give up on dos and move to a more powerful scripting language.
    http://strawberryperl.com/

    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
  6. #4
  7. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2003
    Posts
    1,003
    Rep Power
    32
    I've actually been able to do this with some vb script and DOS...
    Example I create a "CreateSQL.vbs" file with notepad
    Code:
    ' Wscript.Echo  DateAdd("d",-1,Now)
    
    Dim LMon
    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("")
    filetxt.WriteLine("CREATE TABLE PARTDATA.TBLPD" & Year(LMon) & Right("0" & Month(LMon),2) & Right("0" & Day(LMon),2))
    
    filetxt.Close
    and then I call it with a DOS .bat file like
    F:\PathToFile\CreateSQL.vbs
    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"

IMN logo majestic logo threadwatch logo seochat tools logo