Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

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?

You are here: irt.org | FAQ | JavaScript | Date | Q1451 [ previous next ]

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>

©2018 Martin Webb