Help for a date and time string in the format of get-date

When you take a date / time string of an object:

The format of the entry is a string and get-date doesn't seem to be able to convert to the

a System.DateTime.

I want to compare this value to 30 days so there are get-date ((get-date).adddays(-30))

When I try the following, it seems to work then import it:

(get-date - UFormat "%d/%m/%Y %T" ("2010-06-30 00:00:00" ""))

If I add the following:

"[datetime]" (get-date - UFormat "%d/%m/%Y %T" ("2010-06-30 00:00:00" ""))

He can't convert it.

Without the datetime component, when I try a superior test uses only the date

the part as well:

$Test = '2009-10-06 00:00:00.

If ($Test - gt (get-date - UFormat "%T"("06/05/2010 00:00:00") %d/%m/%Y ""))

{

$Tested = 'Yes '.

}

On the other

{

$Tested = 'no '.

}

$tested

Results in a Yes tentatives being earlier.

In the script it returns all records where the date is after

as 05 and ignore the year, month, and time.

Any help with this would be greatly appreciated.

Thank you

This has to do with the 'culture' that you use in your PowerShell session.

You can use the Get-Culture cmdlet to see that one you use.

If you try

[datetime](get-date -UFormat "%m/%d/%Y %T"("30/06/2010 00:00:00"))

The parameter - UFormat produces a string and

the cast is expected default mm/dd/yyyy format, for the part of the date.

So, by reversing the month and day of your UFormat string - that has been corrected.

BTW, I have attached the line because the SW forum do not have hooks.

____________

Blog: LucD notes

Twitter: lucd22

Tags: VMware

Similar Questions

Maybe you are looking for