tags:

views:

620

answers:

3

Converting dates/times into ticks using the PowerShell Get-Date applet is simple. However, how do you do the opposite operation; converting the ticks back into a date and time?

+5  A: 
[DateTime]10000000000
Monday, January 01, 0001 12:16:40 AM

Just cast the number into a DateTime. The DateTime single-parameter constructor takes a long as number of ticks.

Lee
+1 So it does. http://msdn.microsoft.com/en-us/library/aa326681(VS.71).aspx
Robert Harvey
I suspected that it was something simple. This is what happens when you try to learn PowerShell, .NET, and Active Directory at the same time..
mkClark
Welcome to the stack! PowerShell does take a little getting used to, but I really think that it brings a lot of flexibility and strength to Windows that wasn't there before unless you wanted to deal with some sort of Unix toolset like MKSToolkit.
Lee
A: 

Note that you can use the Get-Date cmdlet to also do the reverse operation:

PS> Get-Date 634141193308872671

Mittwoch, 7. Juli 2010 17:08:50
Joey
A: 

You can also use the New-Object cmdlet:

PS > get-date

Friday, July 09, 2010 12:01:42 AM

PS > (get-date).ticks 634142305097923801

PS > New-Object System.DateTime 634142305097923801

Friday, July 09, 2010 12:01:49 AM

Shay Levy