SQL Date in Clojure

Just a small snippet of code for this week. Had a situation where needed to insert a Date value with Korma for one of my databases. Some minor troubleshooting led me to this code snippet that made life a lot easier. Note: the parameter date was a list of strings: (Date, Month, Year).

(defn make-sql-date [date]
  (java.sql.Date.
   (.getTimeInMillis
    (java.util.GregorianCalendar. (Integer. (last date))
                                  (Integer. (second date))
                                  (Integer. (first date))))))
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s