Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
variable to add days to curr date needs to know about next month
Old 11-03-2010, 03:08 PM variable to add days to curr date needs to know about next month
seannarae's Avatar
Skilled Talker

Posts: 65
Location: san francisco, ca
Trades: 0
I have a working set of variables that gets & displays the current date, formats it, then populates a text field with it.

Using that date, i am adding X number of days, and displaying that new date in an LI elsewhere on the page.

The issue is that when i add, for example, 35 days to the current date (11/3/2010), i get an invalid date of (11/38/2010).

How do i get the number of days in any given month?

HERE IS MY HEAD CODE
Code:
var d = new Date();
var day = d.getDate();
var month = d.getMonth() +1;
var year = d.getFullYear();
var today = (month + "/" + day + "/" + year);
    $("#datepicker").val(today);
var dueDate = (month + "/" + (d.getDate()+35) + "/" + year);
    $("#duedatedisp").text(dueDate);
seannarae is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-03-2010, 03:56 PM Re: variable to add days to curr date needs to know about next month
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Code:
var myDate=new Date();
myDate.setDate(myDate.getDate()+35);
Code:
function daysInMonth(p_iMonth, p_iYear)
{
	return 32 - new Date(p_iYear, p_iMonth, 32).getDate();
}
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?

Last edited by chrishirst; 11-03-2010 at 03:58 PM..
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to variable to add days to curr date needs to know about next month
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15411 seconds with 12 queries