MRFerocius
MRFerocius

Reputation: 5629

PowerShell Get -Date

Hi guys I have this in PowerShell:

I have a collection that have a CustomProp named "rep_date" that contains a Date in format: mm/dd/yyyy, now I want to save there the date in this format: dd/mm/yyyy, Im trying this approach:

For ($i=0;$i –le $HD.count; ++$i)
{
    $B = $HD[$i].CustomProps[‘rep_date’] = Get-Date –date $HD[$i].CustomProps[‘rep_date’] -format "dd.mm.yyyy"

    $HD[$i].CustomProps[‘rep_date’] = $B
}

But is not working.

Any ideas on how to accomplish this?

Best Regards!!!

Upvotes: 1

Views: 1351

Answers (2)

Shay Levy
Shay Levy

Reputation: 126712

Try with ToString():

$HD[$i].CustomProps[‘rep_date’] = $HD[$i].CustomProps[‘rep_date’].ToString("dd/MM/yyyy")

Upvotes: 0

Eric Ness
Eric Ness

Reputation: 10417

There are two issues in the code. The first is that the format string should be "dd.MM.yyyy". (Note capital M's) The second is unnecessary assignment of variables. You can just use

$HD[$i].CustomProps[‘rep_date’] = Get-Date –date $HD[$i].CustomProps[‘rep_date’] -format "dd.MM.yyyy"

Upvotes: 2

Related Questions