Day of the week

Hi,
Is there any code/snippet in client side scripting that allows us to evaluate what day of the week has been selected. I want to throw a validation anytime a delivery note is created with a weekend selected as day.
How can i do the same.
Any help will be much appreciated.
Thanks
Nitin

@NitinAgarwal

You can use

var d = frappe.datetime.user_to_obj(frappe.datetime.get_today());

var weekdays = new Array(7);
weekdays[0]=  "Sunday";
weekdays[1] = "Monday";
weekdays[2] = "Tuesday";
weekdays[3] = "Wednesday";
weekdays[4] = "Thursday";
weekdays[5] = "Friday";
weekdays[6] = "Saturday";

var weekday = weekdays[d.getDay()];

Hello @max_morais_dmm
I need to use getDay() or weekday() to know the name of the day for the date, and the date is configured as Date Time field type, I am passing it from javascript to .py to use it there with getDay() or weekday() but it is giving the below error.

But, if I configured the time as now = frappe.utils.now_datetime(), then I can use getDay() or weekday(), it seems there is a problem related to Date Time field type !
How I can overcome this? And why the getDay() or weekday() only work with frappe.utils.now_datetime() and does not work with Date Time field type?

@frappe.whitelist()
def get_customer_subsc(date, party_type, party, docname=None):
post_date = date
now = frappe.utils.now_datetime()
frappe.msgprint(“The day of the post date is {0}”. format(post_date.getDay()))

frappe.msgprint(“The day of the post date is {0}”. format(post_date.getDay()))
AttributeError: ‘unicode’ object has no attribute ‘getDay’

Regards
Bilal

@bghayad Python date objects are quite differently of JS Date objects

from frappe.utils import getdate

@frappe.whitelist()
def get_customer_subsc(date, party_type, party, docname=None):
    postdate = getdate(date)
    print postdate.weekday()
1 Like

It worked fine and wonderful. Thank you a lot.
It seems the structure of the Python date differs than the structure of the JS date.
Regards
Bilal