How can I access the date format from the system settings in Python code?

I am working to retrieve today’s date within an API, but the resulting format does not match the one specified in my system settings. Is there a way to obtain the date that respects the system’s format settings, or alternatively, how can I read the system settings’s date format to apply it manually? like frappe.utills or something else

I am working exclusively with Frappe framework 15 and am not using ERPNext.
I am also using APIs not inside any controller methods.

from datetime import datetime
from frappe.utils import getdate
current_date = datetime.today().date()
print(current_date)   # 2024-11-01
today_date = getdate()
print(today_date)  # 2024-11-01

from frappe.utils import formatdate
current_date = getdate()
date_format = frappe.get_system_settings('date_format')

formatted_date = formatdate(current_date, date_format)
print(formatted_date)

Try this to format the date according to system settings.

1 Like