Solved

handlings dates in javascript

Posted on 2012-03-19
6
191 Views
Last Modified: 2012-03-19
Hi,

I am practicing some JS and have the following question:

An invoice is due and payable in 90 days. Write a function that will display that
date.

I have got as far as the following code however of course this just returns a number.

var now = new Date();
invoice_date = now.getDate()+90;
document.write(invoice_date);

Can someone advise the best way to manage this?
0
Comment
Question by:jecommera
6 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 37737699
check this

var d=new Date();
var milliseconds = d.getTime() + (90*24*60*60*1000);
document.write(new Date(milliseconds));
0
 
LVL 22

Expert Comment

by:Mrunal
ID: 37737704
This returns full date:

<script type="text/javascript">
var myDate=new Date();
myDate.setDate(myDate.getDate()+90);
alert(myDate);
</script>
0
 

Author Comment

by:jecommera
ID: 37737743
Can I get it as just month and date

thanks
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 40

Accepted Solution

by:
gurvinder372 earned 250 total points
ID: 37737773
var d=new Date();
var newDate = new Date( d.getTime() + (90*24*60*60*1000) );
document.write( newDate.getMonth() + " " + newDate.getDate());
0
 
LVL 22

Assisted Solution

by:Mrunal
Mrunal earned 250 total points
ID: 37737816
Here it is:

<script type="text/javascript">
var myDate=new Date();
myDate.setDate(myDate.getDate()+90);

document.write(myDate + "<br/>");
document.write(myDate.getMonth() + "<br/>");
document.write(myDate.getDate());

</script>

Open in new window

0
 
LVL 41

Expert Comment

by:HonorGod
ID: 37738510
This article may also be of interest: http://e-e.com/A_484-Can-I-have-a-date.html
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now