Soleil
Soleil

Reputation: 7459

How to format piped datetime in a custom 24h format in powershell?

I'm selecting all files written since 1 month:

$all = ls -Recurse *mp4 | where {$_.lastwritetime -gt (get-date).adddays(-30)}

and I get only time and size of those files:

$all | select lastwritetime,length

I can get the 24h format with Get-Date -UFormat %R but: how to get this from the last select output ?

I want to reach such formatting: 'dd.hh.mm.ss' with hh in the 24h format.

Upvotes: 1

Views: 777

Answers (2)

Vivek Kumar Singh
Vivek Kumar Singh

Reputation: 3350

Something like this -

$all | select *, @{ name="LastWriteTimeNew"; expression={$_.LastWriteTime.ToString('dd.hh.mm.ss')}} `
| select LastWriteTimeNew, Length

Upvotes: 2

boxdog
boxdog

Reputation: 8442

You can use a calculated property, like this:

Select @{l="LastWriteTime";e={$_.LastWriteTime.ToString("dd.HH.mm.ss")}},length

Upvotes: 2

Related Questions