Matt Pinkston
asked on
Javascript to set Date Variables
I need a javascript that will provide me some date fields based on mondays.
I have a sharepoint custom form that I need to display dates on in the form
mm/dd/yy
Logic
if dow is Monday through Thursday
date1 = current monday
date2 = following monday
date3 = monday 2 weeks out
if dow is Friday through Sunday
date1 = next monday
date2 = 2 mondays out
date3 = 3 mondays out
once I have these in a javascript variable I should be able to produce on form?
I have a sharepoint custom form that I need to display dates on in the form
mm/dd/yy
Logic
if dow is Monday through Thursday
date1 = current monday
date2 = following monday
date3 = monday 2 weeks out
if dow is Friday through Sunday
date1 = next monday
date2 = 2 mondays out
date3 = 3 mondays out
once I have these in a javascript variable I should be able to produce on form?
ASKER
so this script based on dow sets date to = monday's date?
it will simply return you the monday date.
you can always reproduce the current date again, using
var newDate = new Date();
you can always reproduce the current date again, using
var newDate = new Date();
ASKER
so case 0 is SUnday? and so on down the line?
case 0:
date = date + 1; //next monday
break;
On Sunday add 1 to get Mondays date.
case 0:
date = date + 1; //next monday
break;
On Sunday add 1 to get Mondays date.
<<so case 0 is SUnday? and so on down the line?>>
yes
yes
ASKER
how do I add days to get another date?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
this does not seem to work?
<script type="text/javascript">
var date =new Date();
var day = date.getDay();
switch( day )
{
case 0:
date = date + 1; //next monday
break;
case 5:
date = date + 3; //next monday
break;
case 6:
date = date + 2; //next monday
break;
case 1:
date = date + 1; //current monday
break;
case 2:
date = date - 1; //current monday
break;
case 3:
date = date - 2; //current monday
break;
case 4:
date = date - 3; //current monday
break;
}
date1 = date +7;
date2 = date +14;
document.write(date );
document.write(date1 );
document.write(date2 );
</script>
http://www.w3schools.com/jsref/jsref_getday.asp
you can then add the days into current date
i have attached a sample program to get the current/next monday from any day of the week, you can build on that
Open in new window