Home » PowerShell » Convert Timestamp to Date in PowerShell

Convert Timestamp to Date in PowerShell

To convert timestamp to Date in PowerShell, use the .Net method FromFileTimeToUTC(). This method takes Int64 as the input parameter and returns the DateTime.

Windows file time or timestamp is expressed in ticks and a 64-bits signed integer (int64). It represents the number of 100-nanosecond intervals that have elapsed since January 1, 1601 A.D 12:00 midnight.

Convert TimeStamp to DateTime in PowerShell
Convert TimeStamp to DateTime in PowerShell

In this article, we will discuss how to convert timestamp to DateTime in PowerShell.

Convert Int64 TimeStamp to DateTime in PowerShell

.Net DateTime library has the method FromFileTimeUTC() that takes fileTime of int64 as an input parameter and returns the DateTime object that represents the UTC Time equivalent of the date and time.

# Timestamp value
$timestamp = "133174935543788321"  

# Convert timestamp to datetime
[datetime]::FromFileTimeUtc($timestamp) 

In the above PowerShell script, the $timestamp variable stores the int64-bit timestamp value. To get the DateTime from the timestamp, we have used FromFileTimeUtc() method.

It returns the UTC time equivalent date and time for the specified timestamp.

The output of the above PowerShell script to convert the specified windows file time stamp to an equivalent UTC DateTime is:

PS C:\Windows> $timestamp = "133174935543788321"                                                                        

PS C:\Windows> [datetime]::FromFileTimeUtc($timestamp)                                                                  
06 January 2023 15:45:54


PS C:\Windows>                                                                                                                             

Conclusion

I hope the above article on how to convert timestamp to DateTime in PowerShell is helpful to you.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.

Recommended Content

How to Convert String to DateTime in PowerShell

PowerShell Epoch Time and DateTime Conversion

PowerShell Get-Date Minus 1 day

PowerShell Compare File Modified Date

Leave a Comment