Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert sql-timestamp to string in Racket?

The closest thing I came up with looking at the documentation was

(define (sql-datetime->rfc2822 datetime)
  (let ([dt (sql-datetime->srfi-date datetime)])
    (date->string dt (date-display-format 'rfc2822))))

But it fails when I pass it a sql-timestamp

> (sql-datetime->rfc2822 st)
. . date->string: contract violation
 expected: date?
 given: (tm:date 456232000 10 39 18 5 5 2013 0)
in: the 1st argument of
      (->* (date?) (any/c) string?)
contract from: <collects>/racket/date.rkt
like image 965
philix Avatar asked Apr 08 '26 11:04

philix


1 Answers

Prior to Racket version 5.3.4, you need to use the date->string function from the srfi/19 library because the structure types for racket/date and srfi/19 are incompatible (in 5.3.4, which will be released soon, they use the same structure). It should work if you (require srfi/19) and use the API defined there.

like image 83
Asumu Takikawa Avatar answered Apr 10 '26 15:04

Asumu Takikawa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!