Number of day week in javascript
-
Hello everybody, I have a Calendar in my page and I want to check if users select Saturday or Sundays, with getDay() function I can check day number, but I find out depend on operating system setting I get different number for Saturday or Sunday. So how is a proper way I can check this and be sure it is secure for every operating system settings. Regards
Mazy
"This chancy chancy chancy world." -
Hello everybody, I have a Calendar in my page and I want to check if users select Saturday or Sundays, with getDay() function I can check day number, but I find out depend on operating system setting I get different number for Saturday or Sunday. So how is a proper way I can check this and be sure it is secure for every operating system settings. Regards
Mazy
"This chancy chancy chancy world."That's odd behaviour - can you post the code please, including where you Parse the date out (if applicable, including date format)? In any case it probably isn't an OS thing, but a timezone/localisation problem (which happen to be different on the two OSs you are trying). In the mean time you can try
getUTCDay()
, but I doubt it'll fix your problem.KeithBarrow.net[^] - It might not be very good, but at least it is free!
-
That's odd behaviour - can you post the code please, including where you Parse the date out (if applicable, including date format)? In any case it probably isn't an OS thing, but a timezone/localisation problem (which happen to be different on the two OSs you are trying). In the mean time you can try
getUTCDay()
, but I doubt it'll fix your problem.KeithBarrow.net[^] - It might not be very good, but at least it is free!
Thanks, Yes it can be for timezone/localisation problem too. Here is my code: function ff_bfQuickMode7256046_validation(element, message) { if(element.value == '' ) return 'Please select a date for your apppointement.\n'; var myday = new Date(element.value) ; myday.setDate(myday.getDate()); var weekday = myday.getDay(); alert(weekday); if (weekday == 6 || weekday == 0 ) { if (message=='') message = element.name+" faild in my test.\n" message = 'We are close on Saturdays and Sundays.\n'; ff_validationFocus(element.name); return message; } // if return ''; } // ff_bfQuickMode7256046_validation The probelm is I get two different numbers for WEEKDAY on two different computer. So are you telling me that getDay() should return the same value globaly for all OS or setting..?
Mazy
"This chancy chancy chancy world." -
Thanks, Yes it can be for timezone/localisation problem too. Here is my code: function ff_bfQuickMode7256046_validation(element, message) { if(element.value == '' ) return 'Please select a date for your apppointement.\n'; var myday = new Date(element.value) ; myday.setDate(myday.getDate()); var weekday = myday.getDay(); alert(weekday); if (weekday == 6 || weekday == 0 ) { if (message=='') message = element.name+" faild in my test.\n" message = 'We are close on Saturdays and Sundays.\n'; ff_validationFocus(element.name); return message; } // if return ''; } // ff_bfQuickMode7256046_validation The probelm is I get two different numbers for WEEKDAY on two different computer. So are you telling me that getDay() should return the same value globaly for all OS or setting..?
Mazy
"This chancy chancy chancy world."AFAICT it should - people seem to have problems parsing the date in the first place. I'd put a breakpoint on/after this line:
var myday = new Date(element.value) ;
myday
will probably be different across the OSs (and possibly browsers). You might be better off splittingelement.value
yourself and using the constructor functionDate (_year, month, day_)
KeithBarrow.net[^] - It might not be very good, but at least it is free!
-
That's odd behaviour - can you post the code please, including where you Parse the date out (if applicable, including date format)? In any case it probably isn't an OS thing, but a timezone/localisation problem (which happen to be different on the two OSs you are trying). In the mean time you can try
getUTCDay()
, but I doubt it'll fix your problem.KeithBarrow.net[^] - It might not be very good, but at least it is free!
-
AFAICT it should - people seem to have problems parsing the date in the first place. I'd put a breakpoint on/after this line:
var myday = new Date(element.value) ;
myday
will probably be different across the OSs (and possibly browsers). You might be better off splittingelement.value
yourself and using the constructor functionDate (_year, month, day_)
KeithBarrow.net[^] - It might not be very good, but at least it is free!