Somehow frappe.utils.getdate()
changing date format and returning completely a different date of the input. dd-mm-yyyy is set in my ERPNext Setting.
Is this normal? how can I retrieve the weekday name then?
Thanks and Regards
Khaled
Somehow frappe.utils.getdate()
changing date format and returning completely a different date of the input. dd-mm-yyyy is set in my ERPNext Setting.
Is this normal? how can I retrieve the weekday name then?
Thanks and Regards
Khaled
what I know is frappe.utils.getdate
always use yyyy-mm-dd
format
there is frappe.utils.dateutils.parse_date
which convert user_format to yyyy-mm-dd
but I guess it doesn’t work in safe_exec from UI
Workaround solution could be:
date_str = "10-12-2021 23:31:39"
date_format = frappe.db.get_default("date_format") or "yyyy-mm-dd"
date_str = date_str[0:len(date_format)]
dem = "-"
date_format_comp = date_format.split(dem)
if len(date_format_comp) < 3:
dem = "."
date_format_comp = date_format.split(dem)
if len(date_format_comp) < 3:
dem = "/"
date_format_comp = date_format.split(dem)
yyyy_index = date_format_comp.index("yyyy")
mm_index = date_format_comp.index("mm")
dd_index = date_format_comp.index("dd")
date_list = date_str.split(dem)
date_list = [date_list[yyyy_index], date_list[mm_index], date_list[dd_index]]
date_str = "-".join(date_list)
log(date_str)
date = frappe.utils.getdate(date_str)
day = frappe.utils.get_weekday(date)
log(date)
log(day)