|
Q1451 How can I generate a new date for the beginning of the week, ie, generate the date for the Monday, if the date given is the Thursday of that week?
irt.org | Knowledge Base | JavaScript | Date | Q1451 [ previous next ]
Q1451 How can I generate a new date for the beginning of the week, ie, generate the date for the Monday, if the date given is the Thursday of that week?
Try:
<script language="JavaScript"><!--
function Monday(yyyy,mm,dd) {
mm -= 1; // JavaScript months start at 0
theDate = new Date(yyyy,mm,dd);
daynumber = theDate.getDay(); // 0 = monday, 6 = sunday
if (daynumber > 0) daynumber-=1;
else daynumber += 6; // Previous week...
adjust = daynumber*1000*60*60*24;
theMonday = new Date(theDate.getTime() - adjust);
return theMonday.toString();
}
alert(Monday(1999,04,11));
//--></SCRIPT>
|
|
|
Copyright © 1996-2008 irt.org, All Rights Reserved.