IT Community - Software Programming, Web Development and Technical Support

Find the last day of the month for any given month.

This is a discussion on Find the last day of the month for any given month. within the HTML, CSS and Javascript Coding Techniques forums, part of the Web Development category; Hi all... Can anyone tell me how can i find the last day of the month for any given month. ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > HTML, CSS and Javascript Coding Techniques

Register FAQ Members List Calendar Mark Forums Read
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 03-17-2008, 08:51 PM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 547
itbarota is on a distinguished road
Default Find the last day of the month for any given month.

Hi all...


Can anyone tell me how can i find the last day of the month for any given month.



Thanks in advance...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-17-2008, 08:56 PM
Pvinothkumar Pvinothkumar is offline
D-Web Analyst
 
Join Date: Sep 2007
Posts: 237
Pvinothkumar is on a distinguished road
Default Re: Find the last day of the month for any given month.

Hi all...

<script language="JavaScript">
var text = '<table border="0">';

var today = new Date();
/* Test dates */
//today = new Date(2000,2,29);
//today = new Date(1999,1,14);
/*************/

var MonthDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

theYear = today.getYear();
if (theYear < 1000) theYear +=1900;

text += '<tr><td>Today</td><td>: '+today+'</td></tr>';

StartOfThisYear = new Date(theYear,0,1);
EndOfThisYear = new Date(theYear,11,31);

StartOfLastYear = new Date(theYear-1,0,1);
EndOfLastYear = new Date(theYear-1,11,31);

if (today.getMonth()==0) {
StartOfLastMonth = new Date(theYear-1,11,1);
EndOfLastMonth = new Date(theYear-1,11,MonthDays[11]);
}
else {
StartOfLastMonth = new Date(theYear,today.getMonth()-1,1);
LastMonth = today.getMonth()-1;
DaysInLastMonth = MonthDays[LastMonth];
if (LastMonth == 1) { // February
if (theYear%400==0 || (theYear%4 == 0 && theYear%100!=0) ) DaysInLastMonth +=1;
}
EndOfLastMonth = new Date(theYear,today.getMonth()-1,DaysInLastMonth);
}

StartOfLastWeekMS = today.getTime() - ( 24*60*60*1000*(today.getDay()+6) );
StartOfLastWeek = new Date(StartOfLastWeekMS);
EndOfLastWeek = new Date(StartOfLastWeekMS+24*60*60*1000*6);

text += '<tr><td>StartOfLastYear </td><td>: '+StartOfLastYear +'</td></tr>';
text += '<tr><td>EndOfLastYear </td><td>: '+EndOfLastYear +'</td></tr>';
text += '<tr><td>StartOfThisYear </td><td>: '+StartOfThisYear +'</td></tr>';
text += '<tr><td>EndOfThisYear </td><td>: '+EndOfThisYear +'</td></tr>';
text += '<tr><td>StartOfLastMonth</td><td>: '+StartOfLastMonth+'</td></tr>';
text += '<tr><td>EndOfLastMonth </td><td>: '+EndOfLastMonth +'</td></tr>';
text += '<tr><td>StartOfLastWeek </td><td>: '+StartOfLastWeek +'</td></tr>';
text += '<tr><td>EndOfLastWeek </td><td>: '+EndOfLastWeek +'</td></tr>';

text += '</table>';
document.write(text);
</script>


Thanks...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/html-css-javascript-coding-techniques/5447-find-last-day-month-any-given-month.html
Posted By For Type Date
DiscussWeb IT Community - Technical Support and Technology Discussions This thread Refback 03-17-2008 08:53 PM

Similar Threads
Thread Thread Starter Forum Replies Last Post
Number of days in a month (or last day of a month) itbarota HTML, CSS and Javascript Coding Techniques 2 04-28-2008 08:47 PM
Schedule a meeting for the second Tuesday in every other month. itbarota HTML, CSS and Javascript Coding Techniques 1 03-01-2008 03:18 AM
Calculate how many hours per each month itbarota HTML, CSS and Javascript Coding Techniques 1 02-25-2008 09:23 PM
Get Last Day of the Month Function srikumar_l Database Support 0 12-21-2007 08:40 PM
Get First Day of the Month Function srikumar_l Database Support 0 12-21-2007 08:37 PM


All times are GMT -7. The time now is 12:56 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0