PowerShell: Time Stamp Conversion
Summary
Convert 13 digit Value using PowerShell. Why 13 digit? I was querying SharePoint 2010 Document Library for reporting. One of the filed has Number of Downloads values. Initially we thought it's Integer but it was not. The value was like ['\Date(1336721263234)'].
Interface
The Interface of SharePoint site is good
However our customer asked report with date and time stamp in CSV format.
Help
help Get-date -detailed help about_Operators |
Code
We discussed alot with development team about this code format and received multiple answers. The format looks like UNIX oh no may be C#.
Let us show you the final code which gave us promising output. One of my team member made this ugly code and shared with me. Yeah Indeed it gives output.
Function Convert-UnidentifiedDateTime ($weirdvalue) { [timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($weirdvalue)) } $Output = Convert-UnidentifiedDateTIme -weirdvalue 1336636962 $Output |
PowerShell Code
Let's do this the PowerShell way:
"Date and Time Format is {0}" -f (([datetime]'1/1/1970').AddSeconds([int](1336636962564 / 1000))) |
Logic
13 digit value divided by 1000 returns double value - Type cast and ignore values after decimal:
1336636962564 / 1000 |
Now Type Cast
([int](1336636962564 / 1000)) |
Enjoy PowerShell :)