Current Unix Timestamp SECONDS SINCE JAN 01 1970

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

How to convert Datetime to Unix timestamp in VBScript

🎈 🎈 🎈
+1

    Dim dateObj
    Dim unixTimestamp
    
    dateObj = "10/28/2023 12:44:12"
    unixTimestamp = DateDiff("s", "01/01/1970 00:00:00", dateObj)
    
    WScript.Echo "Unix Timestamp: " & unixTimestamp            
        

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

Code Explanation

In this VBScript example the date "10/28/2023 12:44:12" is converted to a Unix timestamp by calculating the number of seconds between the Unix epoch start date ("01/01/1970 00:00:00") and the specified date. This is done using the DateDiff function with the "s" parameter, which indicates that the difference should be calculated in seconds.
The resulting Unix timestamp is stored in unixTimestamp, which is then outputted by the script.



Other useful VBScript date functions

Function Description Example
Now() Returns the current date and time. Now() returns 2024-08-28 12:34:56
Date() Returns the current date. Date() returns 2024-08-28
Time() Returns the current time. Time() returns 12:34:56
DateAdd() Adds a specified time interval to a date. DateAdd("d", 10, "2024-08-28") returns 2024-09-07
DateDiff() Returns the difference between two dates in a specified interval (e.g., seconds, days, months). DateDiff("d", "2024-08-28", "2024-09-07") returns 10
DatePart() Returns a specific part of a given date (e.g., year, month, day). DatePart("m", "2024-08-28") returns 8
DateSerial() Returns a date for the specified year, month, and day. DateSerial(2024, 8, 28) returns 2024-08-28
TimeSerial() Returns a time for the specified hour, minute, and second. TimeSerial(12, 34, 56) returns 12:34:56
Year() Returns the year of a specified date. Year("2024-08-28") returns 2024
Month() Returns the month of a specified date. Month("2024-08-28") returns 8
Day() Returns the day of the month of a specified date. Day("2024-08-28") returns 28
Weekday() Returns the day of the week for a specified date. Weekday("2024-08-28") returns 4 (Wednesday)
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