Filters for date in erpnext15

In ERPNext v15, how can I set a filter for a date?

For example:

  • From Date: 18/01/2025 (10 days before today)
  • To Date: 28/01/2025 (Today)

I want to set this in the filter fields of report.

If your report is Script or Query Report, check this :point_down:

frappe.query_reports["Report Name"] = {
	filters: [
		{
			fieldname: "from_date",
			label: __("From Date"),
			fieldtype: "Date",
			width: "40",
			default: frappe.datetime.get_today(),// Here you can set the default value of the date field
			reqd: 1,
		},
		{
			fieldname: "to_date",
			label: __("To Date"),
			fieldtype: "Date",
			width: "40",
			default: frappe.datetime.get_today(),// Here you can set the default value of the date field
			reqd: 1,
		},
	],
};

I


want a date range where the “from date” is 10 days before today’s date, and the “to date” is today’s date.

For example, if today is January 31, 2025, then:
:white_check_mark: From date: January 21, 2025 (10 days before today)
:white_check_mark: To date: January 31, 2025 (today’s date)

frappe.query_reports["Your Report Name"] = {
	"filters": [
		{
			"fieldname": "from_date",
			"label": __("From Date"),
			"fieldtype": "Date",
			"default": frappe.datetime.add_days(frappe.datetime.get_today(), -10), 
			"reqd": 1
		},
		{
			"fieldname": "to_date",
			"label": __("To Date"),
			"fieldtype": "Date",
			"default": frappe.datetime.get_today(), 
			"reqd": 1
		}
	]
};

plz check this @jankijoshi

1 Like

I have tried this but is not working, even I tried in script section, as you said but still it is not working @Vipul_Kumar

You have to write this code in the js file of this Early Going Employee Report. In your code editor add this code. Is it a custom Script report?

It is a Query Report and can’t we add those filters directly in the default field of filter table.