Important alert: (current site time 7/15/2013 12:25:42 PM EDT)
 

VB icon

Add months to a date/format output

Email
Submitted on: 6/1/1998
By: Found on the Web 
Level: Not Given
User Rating: By 2 Users
Compatibility: JavaScript
Views: 19485
 
     How do you add a number of months to a date and then format the output? Found in the Javascript FAQ at:http://www.btinternet.com/~martin.webb/faqqa/fdate.html#1
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Add months to a date/format output
' Description:How do you add a number of months to a date and then format the output?
Found in the Javascript FAQ at:http://www.btinternet.com/~martin.webb/faqqa/fdate.html#1
' By: Found on the Web
'
' Assumes:Which when run produces: 
2nd December 1998 
'**************************************

<SCRIPT LANGUAGE="JavaScript"><!--
function makeArray() {
for (i = 0; i<makeArray.arguments.length; i++)
this[i + 1] = makeArray.arguments[i];
}
var months = new makeArray('January','February','March','April',
'May','June','July','August','September',
'October','November','December');
function nths(day) {
if (day == 1 || day == 21 || day == 31) return 'st';
else if (day == 2 || day == 22) return 'nd';
else if (day == 3 || day == 23) return 'rd';
else return 'th';
}
function y2k(number) { return (number < 1000) ? number + 1900 : number; }
function monthsahead(noofmonths) {
var today = new Date();
var date = new Date(today.getYear(),today.getMonth() + noofmonths,today.getDate(),today.getHours(),today.getMinutes(),today.getSeconds());
return date.getDate() + nths(date.getDate()) + ' ' + months[date.getMonth() + 1] + ' ' + y2k(date.getYear());
}
document.write(monthsahead(6));
//--></SCRIPT>


Other 219 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

11/7/1999 6:37:00 AMKISA

HELLO
(If this comment was disrespectful, please report it.)

 
7/12/2002 4:26:55 AMling

Do you know how to compare a date?for example the end date should not be earlier than a start date? pls help..thanks
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.