Appending date/time to the log file name... Windows has me stumped

Currently reading
Appending date/time to the log file name... Windows has me stumped

4,027
1,378
NAS
DS4l8play, DS202j, DS3623xs+, DSM 7.3.3-25847
Last edited:
I'm running a simple task that creates a log file. But I've been unsuccessful getting a timestamp appended to the filename.

Basically I have working in PowerShell...
foobar.exe -logs > .\mylogs\record.log

What I want the output file to be named is record-20221128-023321.log. Either I'm too dense to figure this out, or this is a place where Windows comes up short in contrast to Linux.

With Debian I use this...
foobar.exe -logs > .\mylogs\record-$(date +\%Y\%m\%d-\%H\%M\%S).log

Of course Windows has no part of that.

I've spent most of a day trying to sort through this, but alas, Google has not been cooperative.

On the off-chance someone here might know some Windows command voodoo... I'm hoping for a hint of what to do. Thanks all!
 
Its been a while and my PS-fu is a little rusty, but I think you need the Get-Date cmdlet...and use the -Format or -UFormat flags, eg

Code:
Get-Date -Format "dddd MM/dd/yyyy HH:mm:ss "

...uses the .Net formatting style. Or, to use the UFormat style which is more Linux-like:

Code:
Get-Date -UFormat "%m %d %Y %R "

See link for details of the UFormat elements.

These are the basics but you'll hopefully get the gist.
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Similar threads

In the past few years, I've created "Projects" for me to Keep all things here fully Updated.... What...
Replies
0
Views
333
Because all the people (3) in the tapes are no more..... The challenge was getting tapes to play... But...
Replies
2
Views
1,218

Welcome to SynoForum.com!

SynoForum.com is an unofficial Synology forum for NAS owners and enthusiasts.

Registration is free, easy and fast!

Back
Top