Kaseya Community

Date/Time Stamp

  • Anyone figure out how to create a variable for a date/time stamp?

    I need to create a file with the date/time in the file name. I tried ussing the %DATE% variable from inside a shell command but has slashes (/) between the day/month/year and therefor crestes a folder for each date.

    Any help is appreciated! Example of filename neededis:

    041607filename.txt


    Legacy Forum Name: Date/Time Stamp,
    Legacy Posted By Username: rage
  • It takes a few commands but you can do it this way:

    DATE /T > date.txt
    FOR /F "tokens=2,3* delims=/ " %i in (date.txt) do @ECHO %i%j%k > shortdate.txt

    the date format will output as 04172007

    then just read the "shortdate.txt" into a variable.

    Keep in mind that when you use these commands in a K script that you have to enter double > since they are an escape character for them. I left them as they are so you can just paste those lines into a DOS window and see what the result is. You can do a "type date.txt" and a "type shortdate.txt"to see the contents of the files. If you want to know what I did in the FOR statement, just type "FOR /?" and read through the help. It is an extremely useful command.

    Hope that helps.

    --Brian


    Legacy Forum Name: Script Requests,
    Legacy Posted By Username: byulke