Reputation: 2759
I have the following
foreach($res in $result1)
{
$ed = $res.EVENT_DATE
}
$ed
is
29 September 2015 00:00:00
(It comes out of a MySQL Database as '2015-09-29' - but I'm assuming powershell is being 'clever' and converting it).
However, I need it to display as '
2015-09-27
I tried:
$ed = $res.EVENT_DATE
$ed = get-date -date $ed
With the intention of then formatting it accordingly, But this gives me
Get-Date : Cannot bind parameter 'Date' to the target.
Exception setting "Date": "Object reference not set to an instance of an object."
What is the correct way of formatting this to display as required?
Upvotes: 0
Views: 1984
Reputation: 6605
How Powershell displays it depends on your locale info. For example:
D:\> get-date "29 September 2015 00:00:00"
Tuesday, September 29, 2015 12:00:00 AM
D:\> get-date "29 September 2015 00:00:00" -Format yyyy-MM-dd
2015-09-29
so you might try this:
foreach($res in $result1)
{
$ed = get-date $res.EVENT_DATE -format yyyy-MM-dd
}
Upvotes: 1