Current Unix Timestamp SECONDS SINCE JAN 01 1970

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

How to convert Datetime to Unix timestamp in Scheme

🎈 🎈 🎈
+1

    (import (srfi 19))

    (define my-date (make-date 0 30 12 15 7 2018 0)) ; Date: 2018-07-15 12:30:00
    (define unix-timestamp (date->seconds my-date))
    
    (display unix-timestamp)
    (newline)            
        

Output:
1531656600
Example only. There may be multiple ways to perform this operation.

Code Explanation

In this Scheme example, a date object is created for '2018-07-15 12:10:00' using the make-date function, which allows you to specify the second, minute, hour, day, month, year, and time zone. The date->seconds function converts this date structure to a Unix timestamp.
The result is then printed using display.



Other useful Scheme date functions (SRFI-19)

Function Description Example
seconds->date Converts a Unix timestamp (in seconds) to a date structure. (seconds->date 1514764800) returns 2018-01-01 00:00:00+00:00
date->seconds Converts a date structure to a Unix timestamp. (date->seconds (make-date 0 30 12 15 7 2018 0)) returns 1531656600
make-date Creates a date structure from second, minute, hour, day, month, year, and time zone components. (make-date 0 30 12 15 7 2018 0) creates the date 2018-07-15 12:30:00.
date->string Converts a date structure to a formatted string. (date->string date) returns a formatted string like 2018-07-15 12:30:00+00:00.
current-date Returns the current date as a date structure. (current-date) returns the current date and time.
date-year Extracts the year from a date structure. (date-year (current-date)) returns the current year.
date-month Extracts the month from a date structure. (date-month (current-date)) returns the current month.
date-day Extracts the day of the month from a date structure. (date-day (current-date)) returns the current day of the month.
date-hour Extracts the hour from a date structure. (date-hour (current-date)) returns the current hour.
date-minute Extracts the minute from a date structure. (date-minute (current-date)) returns the current minute.
date-second Extracts the second from a date structure. (date-second (current-date)) returns the current second.
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