On this page:
datetime
datetime?
jd->datetime
posix->datetime
datetime->iso8601
datetime=?
datetime<?
datetime<=?
datetime>?
datetime>=?
datetime-order
6.3.90.900

4 Combined Date and Time

The datetime struct represents the combination of a date and a time; that is, it represents a date at a particular time-of-day. However, it does not include time zone information, so it does not represent an absolute moment in time.

procedure

(datetime year    
  [month    
  day    
  hour    
  minute    
  second    
  nanosecond])  datetime?
  year : exact-integer?
  month : (integer-in 1 12) = 1
  day : (day-of-month/c year month) = 1
  hour : (integer-in 0 23) = 0
  minute : (integer-in 0 59) = 0
  second : (integer-in 0 59) = 0
  nanosecond : (integer-in 0 999999999) = 0
Constructs a datetime with the given date and time fields.

Examples:
> (datetime 1970)

#<datetime 1970-01-01T00:00:00>

> (datetime 1969 7 21 2 56)

#<datetime 1969-07-21T02:56:00>

procedure

(datetime? x)  boolean?

  x : any/c
Returns #t if x is a datetime; #f otherwise.

procedure

(jd->datetime jd)  datetime?

  jd : real?
Returns the datetime corresponding to the given Julian day, which is the number of solar days that have elapsed since 12:00 UT on November 24, 4714 BC in the proleptic Gregorian calendar.

Examples:
> (jd->datetime 0)

#<datetime -4713-11-24T12:00:00>

> (jd->datetime 2440587.5)

#<datetime 1970-01-01T00:00:00>

procedure

(posix->datetime posix)  datetime?

  posix : real?
Returns the datetime corresponding to the given POSIX time, which is the number of seconds that have elapsed since 00:00 UTC on January 1, 1970.

Examples:
> (posix->datetime 0)

#<datetime 1970-01-01T00:00:00>

> (posix->datetime 2147483648)

#<datetime 2038-01-19T03:14:08>

procedure

(datetime->iso8601 dt)  string?

  dt : datetime?
Returns an ISO 8601 string representation of dt.

Examples:
> (datetime->iso8601 (datetime 1970))

"1970-01-01T00:00:00"

> (datetime->iso8601 (datetime 1969 7 21 2 56))

"1969-07-21T02:56:00"

> (datetime->iso8601 (datetime 1 2 3 4 5 6 7))

"0001-02-03T04:05:06.000000007"

procedure

(datetime=? x y)  boolean?

  x : datetime?
  y : datetime?

procedure

(datetime<? x y)  boolean?

  x : datetime?
  y : datetime?

procedure

(datetime<=? x y)  boolean?

  x : datetime?
  y : datetime?

procedure

(datetime>? x y)  boolean?

  x : datetime?
  y : datetime?

procedure

(datetime>=? x y)  boolean?

  x : datetime?
  y : datetime?
Comparison functions on datetimes.

Examples:
> (datetime=? (datetime 1970 1 1) (datetime 1970))

#t

> (datetime<? (datetime 1970) (datetime 1969 7 21 2 56))

#f

> (datetime>? (datetime 1970) (datetime 1969 7 21 2 56))

#t

An order defined on datetimes.

Examples:
> (datetime-order (datetime 1970 1 1) (datetime 1970))

'=

> (datetime-order (datetime 1970) (datetime 1969 7 21 2 56))

'>

> (datetime-order (datetime 1969 7 21 2 56) (datetime 1970))

'<

> (make-splay-tree datetime-order)

#<compact-splay-tree*>