Solved

handlings dates in javascript

Posted on 2012-03-19
6
213 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to print dynamic Google map and directions? 1 23
jQuery Scroll To Top 5 38
Html value of radio 14 28
JS Event Does not Trigger From File 2 26
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

856 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