Current Unix Timestamp SECONDS SINCE JAN 01 1970

Current UTC Time
2025-08-20
Convert Datetime to Unix Timestamp in Powershell

How to convert Datetime to Unix timestamp in Powershell

🎈 🎈 🎈
+1

    # Convert Date to Unix timestamp
    $date = Get-Date "2015-11-23 07:12:04"
    $unixEpoch = Get-Date "1970-01-01 00:00:00"  # Unix epoch start
    $unixTimestamp = [int]($date - $unixEpoch).TotalSeconds
    
    Write-Output "Unix Timestamp: $unixTimestamp"            
        

Output:
Unix Timestamp: 1448262724
Example only. There may be multiple ways to perform this operation.

Code Explanation

In this example of date to Unix timestamp conversion in Powershell, a date (2015-11-23 07:12:04) is subtracted from the Unix epoch (1970-01-01 00:00:00).
The difference is calculated in seconds using the TotalSeconds property. The result is cast to an integer, and the result, which is the Unix timestamp, is printed. For '2015-11-23 07:12:04', the result is 1448262724.


Other useful Powershell date functions

Function Description Example
Get-Date Returns the current date and time or a specified date. Get-Date "2018-07-15 12:30:45" returns 2018-07-15 12:30:45
AddSeconds() Adds a number of seconds to a DateTime object. (Get-Date).AddSeconds(86400) adds 1 day to the current date.
AddDays() Adds a number of days to a DateTime object. (Get-Date).AddDays(7) adds 7 days to the current date.
AddHours() Adds a number of hours to a DateTime object. (Get-Date).AddHours(3) adds 3 hours to the current time.
TotalSeconds Returns the total seconds between two dates. ($date - $unixEpoch).TotalSeconds returns the seconds between two dates.
Set-Date Changes the system date and time to a specified date and time. Set-Date "2024-08-28 12:00:00" sets the system date to 2024-08-28 12:00:00.
ToString() Formats a DateTime object into a string using a specified format. (Get-Date).ToString("yyyy-MM-dd HH:mm:ss") returns 2024-08-28 12:34:56
New-TimeSpan Calculates the difference between two dates. New-TimeSpan -Start (Get-Date "2018-01-01") -End (Get-Date "2020-01-01") returns the difference between the two dates.
Get-ItemProperty Retrieves system or file date properties (e.g., created or modified dates). Get-ItemProperty "C:\file.txt" | Select-Object LastWriteTime
Current Unix Timestamp SECONDS SINCE JAN 01 1970

Current UTC Time
2025-08-20
Ad Banner Placeholder
Ad Banner Placeholder
Ad Banner Placeholder
Ad Banner Placeholder