Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.