REBOL [
    Title: "SQL date 23"
    Purpose: {This is a function that takes a R-E-B-O-L date
    and returns it in yyyy-mm-dd format which is suitable for
    using in an SQL "where" condition where one is selecting
    data by date.}
]

;; [---------------------------------------------------------------------------]
;; [ This is a function to save some annoying fussing.                         ]
;; [ It takes a REBOL date and returns YYYY-MM-DD which is a form of the       ]
;; [ date that can be used in an SQL "where" condition.                        ]
;; [ This is the format "23" date used in T-SQL date conversion.               ]
;; [ This function is another variation of an idea from the REBOL cookbook,    ]
;; [ and copied heavily from there as you would see if you would check.        ]
;; [---------------------------------------------------------------------------]

SQL-DATE-23: func [
    REBOL-DATE
    /local DATE-23 add2
] [
    add2: func [num] [ ; always create 2 digit number
        num: form num
        if tail? next num [insert num "0"]
        append DATE-23 num
    ]
    DATE-23: form REBOL-DATE/year
    append DATE-23 "-"
    add2 REBOL-DATE/month
    append DATE-23 "-"
    add2 REBOL-DATE/day
    return DATE-23
]

;;Uncomment to test
;print SQL-DATE-23 now
;halt