views:

260

answers:

2

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!!!

+2  A: 

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"
Eric Ness
A: 

Try with ToString():

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

Shay Levy