Monthly Archive

Categories

Date Display

While playing round with the dates for the previous post I made an odd discovery.

PS> Get-Date

27 August 2008 22:09:50

PS> $now = Get-Date
PS> $now

27 August 2008 22:09:59

PS> "Now: $($now)"
Now: 08/27/2008 22:09:59
PS>
PS> "Now: $(get-date)"
Now: 08/27/2008 22:10:37

Notice how the date and time are displayed in get-date and when setting it to  a variable.  If I now try to substitute that into a string notice how it changes.

To get it to display the way I want I need to specifically format the date and time

PS> "Now: $(get-date -format F)"
Now: 27 August 2008 22:18:10

$now = get-date -format F

PS> "Now: $($now)"
Now: 27 August 2008 22:18:35

An oddity but one I'd not seen before and something to be aware of.

 

Share this post :

Technorati Tags: Powershell

Leave a Reply