0

I'm writing a script to check what is the last time a snapmirror relationship has been updated using PowerChell over cluster mode netapps.

I found that using snapmirror show on the CLI I could see "last transfer end timestamp" and there is also a property with the same name using PowerShell using:

get-ncsnapmirror | select lasttransferendtimestamp

Problem is at the CLI it shows a nice date (08/23 22:05:51) and using PowerShell all I get is a number (1471979101). Does anyone know how I could translate this number to a DateTime format? (.ToDateTime() didn't work)

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Tomer Schweid
  • 325
  • 2
  • 5
  • 18

1 Answers1

1

It shows the total seconds from the beginning of UNIX time. So you could do:

$date = Get-Date -Year 1970 -Month 1 -Day 1 -Hour 00 -Minute 00 -Second 00
$date.AddSeconds($integer)

EDIT : After Ansgar Wiechers's comment.

$date = (Get-Date '1970-01-01').AddSeconds($integer)

Where $integer is the number you get. The result that I get is:

PS C:\> $date = (Get-Date '1970-01-01').AddSeconds(1471979101)
PS C:\> $date.GetDateTimeFormats('s')
2016-08-23T19:05:01
Syphirint
  • 1,021
  • 2
  • 13
  • 24
  • That's seems pretty close, but somehow I get a 5 hours difference between the two (19:05 and 22:05), I thought it might be a timezone problem but when I typed date at the netapp I got the same hour as my PC. Any ideas why? Or would you just recommend to add 05 to hours at the beginning? – Tomer Schweid Aug 24 '16 at 09:28
  • @TomerSchweid That's probably a timezone offset. Try `$date.AddSeconds(1471979101).ToLocalTime()`. – Ansgar Wiechers Aug 24 '16 at 09:32
  • 1
    @Syphirint Shorter: `(Get-Date '1970-01-01').AddSeconds($integer)` – Ansgar Wiechers Aug 24 '16 at 09:33