How do we get time stamp with file name by using batch script in Windows Server 2022 Datacenter 64-bit Version 21H2(Build 20348.1487)

moulali d 0 Reputation points
2023-01-19T07:33:39.7133333+00:00

I am unable to get the time stamp in file name by using batch script in Windows Server 2022 Datacenter 64-bit Version 21H2(Build 20348.1487). Could you please help me on this.

Windows for business | Windows Server | User experience | PowerShell
Windows for business | Windows Server | User experience | Other
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Olaf Helper 47,441 Reputation points
    2023-01-19T07:51:21.6+00:00

    That's to less on informations, please provide more details.

    Which scripting language, how does your current script look like and whats's the timestamp format in the file name?

    0 comments No comments

  2. Limitless Technology 44,766 Reputation points
    2023-01-19T13:40:08.56+00:00

    Hello,

    In CMD batch files generally the solution is quite simple — we should use the %date% and %time% built-in variables, that display date and time based on the regional coding. for date echo %date% for time echo %time% just add in front of output file name in connect script for example - "D:\path\outfile_%date%%time%"

    --If the reply is helpful, please Upvote and Accept as answer--

    0 comments No comments

  3. Rich Matheisen 47,901 Reputation points
    2023-01-19T15:44:05.19+00:00

    Are you trying to rename a file by adding its creation date to the existing file name? If so, something like this will work:

    $x = get-item C:\junk\dp.txt
    $date = get-date $x.CreationTime -Format "yyyy MM dd"
    $x | Rename-Item -Name ("{0}_{1}" -f $date, $x.Name)
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.