[racket] date format conversion

From: Neil Van Dyke (neil at neilvandyke.org)
Date: Sat Feb 12 20:32:39 EST 2011

prad wrote at 02/12/2011 08:17 PM:
> is there a function which will convert
> "February 12, 2011"
> to
> "2011-02-12"

Racket search turns up "string->date" and "date->string".  You can use 
them to define your new procedure like this...

;;;; BEGIN

#lang racket/base

(require srfi/19)

(define (us-long-date-str->iso-8601-date-str long-date-str)
  (date->string (string->date long-date-str
                              "~B ~d, ~Y")
                "~Y-~m-~d"))

(require test-engine/racket-tests)
(check-expect (us-long-date-str->iso-8601-date-str "February 12, 2011") 
"2011-02-12")
(check-expect (us-long-date-str->iso-8601-date-str "February 09, 2011") 
"2011-02-09")
(check-expect (us-long-date-str->iso-8601-date-str "February 9, 2011")  
"2011-02-09")
(test)

;;;; END

-- 
http://www.neilvandyke.org/


Posted on the users mailing list.