JavaScript - Getdate Help Please
I'm trying to get the day of the week to show up as a number on the page.
The problem is, no matter what I try, it's coming back as 4. I made this alert to test the code. This alert works UNLESS anything else is ordered before +monthBirth. If the order is changed it adds it together which I guess is because of the plus. Code: alert(+monthBirth +dateBirth +yearBirth) What I want is the day of the week to show up as a number on the page. I think the reason I keep getting 4 is due to something with the addition problem I have? But I really have no idea at all. Can anyone please help? Code: <html> <head> <script> MONTHS_OF_THE_YEAR = 'janfebmaraprmayjunjulaugsepoctnovdec'; MILLISECONDS_DAY = 1000*60*60*24; MILLISECONDS_YEAR = 1000*60*60*24*365.2424; LIFE_EXPECTANCY = 1000*60*60*24*365.2424*67.2; var daysArray = new Array ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); var yearBirth = ''; yearBirth = prompt('Please enter your year of birth'); var monthBirth = ''; monthBirth = prompt('Please enter your month of birth'); monthBirth = monthBirth.slice(0,3); monthBirth = monthBirth.toLowerCase(); monthBirth = MONTHS_OF_THE_YEAR.indexOf(''+monthBirth)/3; var dateBirth = ''; dateBirth = prompt('Please enter your date of birth'); alert(+monthBirth +dateBirth +yearBirth) var dd=new Date(+monthBirth); dd=dd.getDay(); document.write(dd); </script> </head> <body> </body> <html> Similar TutorialsI'm trying to make it so that on holidays, my page will say Happy"so and so..." at the top. I only started this 5 minutes ago so that's why it's so under developed. Here's what I have. I'm wanting to know if "today.getMonth.getDate" is valid or would I have to do something else. function startTime() { var today=new Date(); var hol=today.getMonth.getDate() if (hol==4+1) p.s I only want the holiday. I already have a clock but I want them to be separate. Okay, I've posted the code with just the two fields needed to solve my problem. If I type in a date of 04/16/2011 in the "sentence date" field, then click the calculate button, the date 03/05/2011 is displayed in the "Due to Reviewer" field. It subtracts 42 days from the date enetred into the "Sentence Date" field. My problem is, sometimes when I type in a date in the "Sentence Date", such as 04/16/2011, 42 days prior falls on a weekend & I need it to always be on a weekday. So with that said, is it possible to put some type on function in the code where if the date falls on a weekend (Saturday or Sunday), it will roll back & display Friday's date? Thanks again for the help! <html> <head> <script type="text/javascript"> var valid; function d2(v) { return (v<10)?("0"+v):v; } function dcheck(form) { var s = form.sent_date.value; var sent = new Date(s); var dr = form.due_rev.value var due_rev = new Date(dr); if (isNaN(due_rev)) { due_rev = new Date(sent.getFullYear(),sent.getMonth(),sent.getDate()-42); } form.sent_date.value = (sent.getFullYear()+0) + "-" + d2(sent.getMonth()+1) + "-" + d2(sent.getDate()); form.due_rev.value = (due_rev.getFullYear()+0) + "-" + d2(due_rev.getMonth()+1) + "-" + d2(due_rev.getDate()); return true; } </script> </head> <body> <form method="post" action="add.php"> </select> </br> <b>Sentence Date: MM/DD/YYYY</b> <br /> <input type="text" name="sent_date" size="30" /><br /> <p><input type="button" value="Calculate" onclick="return dcheck(this.form);"> </p> <b>Due to Reviewer:</b> <br /> <input type="text" name="due_rev" size="30" /><br /> <br> </form> </body> </html> |