Solved

# Check weekday

Posted on 2007-11-14
953 Views
I need to validate that a form field is a particular weekday (say Saturday).  The field is submitted in yyyy-mm-dd format.
0
Question by:Orroland
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2

LVL 21

Expert Comment

ID: 20282332
Here is a simple example, which may help:

<script type="text/javascript">

// 2007 January 14th as an example
var d=new Date(2007,0,14)

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

document.write("Today it is " + weekday[d.getDay()])

</script>

Hope this helps.
0

LVL 54

Accepted Solution

b0lsc0tt earned 500 total points
ID: 20282423
Orroland,

The function below will take the field value, process it and check for the weekday.

function myDate(val) {
var arDate = val.split("-");
if (arDate.length != 3) {
return false;
}
var yr = arDate[0];
var mnth = arDate[1];
var dy = arDate[2];
var dte = new Date();
mnth = mnth - 1;
dte.setFullYear(yr);
dte.setMonth(mnth);
dte.setDate(dy);
var wkdy = dte.getDay();
if (wkdy != 6) { // Saturday, days start at 0 for Sun
return false;
}
return true;
}

Let me know how that works.  I can modify or help you use it if needed.  Let me know if you have any questions or need more information.

b0lsc0tt
0

LVL 54

Expert Comment

ID: 20284937
I'm glad that helped.  Thanks for the grade, the points and the fun question.

bol
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

Put javascript to get dropdown value 3 33
how to use string functions to get particular string 3 51
Slush on text 2 26
Difference between Highcharts and Mapbox 10 44
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
###### Suggested Courses
Course of the Month6 days, 14 hours left to enroll