Reputation: 1680
I would like to add a condition in my query to filter records which has a date falling under current month. How can I achieve this? I tried to use clj-time to retrieve the current month and match it along with the DB field. But that didn't give me any luck.
Upvotes: 0
Views: 60
Reputation: 51450
Actually, it's pretty simple to determine the current month using clj-time
:
(month (now)) ; number from 1 to 12
But, since you're trying to query a database, you should be interested with the beginning of the current month:
(let [t (now)]
(date-time (year t) (month t)))
This code will return you a valid DateTime
object, corresponding to the beginning of the current month. You can use this object t query your SQL database:
(select objects
(where {:created [> start_of_the_current_month]}))
Upvotes: 1