Date Functions with mongo db

Hi All,

My query connects to Mongo from Redash. I am trying to filter the data not to have the current month. when I use This month in filter it is using the current date to filter, when i use last month it takes the first day of the last month.

Please let me know how to get the last date of the previous month that can be used to filter the date

Thanks,
Vijay K

You can use the humanTime value end of last month like this.

{
	"collection": "demo-db",
	"query": {
		"someDateTimeField": {
			"$lt": {
				"$humanTime": "end of last month"
			}
		}
	},
	"limit": 100
}

Thanks for replying Jesse, end of last month or last day of last month is not working properly. It give me 8th month last date (I tried it on 31st October)

Strange. It works as expected on my end.

Another option is start of this month using $lt

Hi Jesse,

thanks for replying. start of this month worked, but need to check for couple of days and confirm it…

Appreciate your help.

Thanks,
Vijay