Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JavaScriptQuestions javascript date difference in months
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


ratna rathor
javascript date difference in months
1 Answer(s)      2 years and 5 months ago
Posted in : JavaScript Questions


How can I find the difference between two dates in terms of months using javascript?


Advertisement
View Answers

May 15, 2012 at 1:28 PM


<html>
<head>
<script type="text/javascript">

var date1=new Date();
var date2 =new Date("Jan, 11, 2000")
var yearDiff=date1.getFullYear()-date2.getFullYear();

var y1=date1.getFullYear();
var y2=date2.getFullYear();

var monthDiff=(date1.getMonth() + y1*12)-(date2.getMonth() +y2*12);
document.write("Date difference in month : "+monthDiff);
</script>
</head>
</html>

Description: In javascript whenever you write new Date() it shows the current date in standard format with current day,date,time and GMT.you can also specify your own date by using new Date(). You can get number of years of specified date by using getFullYear() function and number of months by using getMonth() method .To get the date difference in months you must also consider years diffrence.



Related Tutorials/Questions & Answers:
javascript date difference in months
javascript date difference in months  How can I find the difference between two dates in terms of months using javascript?   <html>... of months by using getMonth() method .To get the date difference in months you
javascript date difference in days.
javascript date difference in days.   I want to find the difference between two dates in terms of days. I am using javascript. Please help.  ... of days by using method getDay(). Now to find date difference
Advertisements
javascript date difference in years
javascript date difference in years  I want to find the difference between two dates with respect to years. I am using javascript. Please help.  ...=date1.getFullYear()-date2.getFullYear(); document.write("Date difference in years : "+yearDiff
JavaScript Date Difference
JavaScript Date Difference...;Date Difference</h2> <script type="text/javascript"> var...; In this section, we are going to determine the difference between two dates
Java date add months
Java date add months In this tutorial, you will learn how to add months to date. Here, we are going to add few months to current date and return the date... have added 4 months to the calendar and using the Date class, we have got
Java subtract months from date
Java subtract months from date In this tutorial, you will learn how to subtract months from date. Using the Calendar class, you can add and subtract date...(-). This will reduce date from date. Here, we are going to subtract few months
Ask date difference
dates from the user and calculates the date difference in terms of days. import...Ask date difference  Hello, I have a problem about how to calculate date, the result from this code is not complete , this is my code . please help
What is difference between the java and javascript?
What is difference between the java and javascript?  What is the difference beteen the java and javascript?   Hello Friend, Read Here Thanks
javascript date comparison
javascript date comparison  How to compare dates and display... language="JavaScript"> var date1 = new Date("jan, 25, 2010"); var today = new Date(); var difference = today - date1; var days =parseInt(difference
javascript date picker - Date Calendar
javascript date picker  how to insert a date picker user control in a html/jsp using javascript??? please help, it's urgent.  Hi Friend, Please visit the following links: http://www.roseindia.net/javascript
Date object using JavaScript
Date object using JavaScript  What's the Date object using JavaScript
What is difference between the java and javascript?
What is difference between the java and javascript?  What is the difference beteen the java and javascript?   Hello Friend, Difference: 1..., while JavaScript is a scripting language that was introduced by Netscape. 2
javascript questions on date
javascript questions on date  how to add some days to an existing date
javascript tomorrow date.
javascript tomorrow date.  Hi, how can I display tomorrow's date using javascript?   <html> <head> <title>Date after current date</title> <script type="text/javascript"> var mydate= new
javascript yesterday date.
javascript yesterday date.  Hi, How can I display the yesterday's... date</title> <script type="text/javascript"> var mydate= new Date...;/head> </html> Description: In javascript whenever you write new Date
javascript current date and time.
javascript current date and time.  How can we display current date and time using javascript?   <html> <head> <title>Current date and time</title> </head> <script type="text/javascript
JavaScript Validate UK Date
JavaScript Validate UK Date  How to Validate UK Date in JavaScript... if (!validformat.test(input.value)) alert('Invalid Date Format. Please correct.') else{ //Detailed check for valid date ranges var
date format in javascript
date format in javascript  display date format as dd/mm/yyyy and day... help me. thank u var date=/^\d{2}\/\d{2}\/\d{4}$/ if(document.userform.joindate.value.search(date)==-1) { alert("please enter date format as dd/mm/yyyy
Transaction in last 3 months
to calculate amount submitted through transactions in last three months. I have to check the date of all transactions in past 90 days and add the total amount submitted. What query can i use to get all the transactions in past 3 months starting
JavaScript Show Date
JavaScript Show Date..., we are going to display the current date using JavaScript. You can see... Date</h2> <script type="text/javascript"> var date = new
JavaScript parse date
JavaScript parse date..., you will learn how to parse the date in JavaScript. JavaScript provides the function parse() that takes a date in string format and returns the equivalent
start date and end date validation in javascript - Ajax
start date and end date validation in javascript  hi, i am doing web surfing project. pls guide me for my project. i want start date and end validations in javascript. end date should be greater than start date if so less than
javascript date validation using regex
javascript date validation using regex  Hi, I want to validate the date using javascript. Please help.   <html> <head> <title>Validating Date format</title> <script type="text/javascript">
Date Difference
Date Difference       This example learns how to make the difference between two dates and how... Object class and makes a difference between a Date object and a set of integer
JavaScript calendar date picker
: bold; } .style1 { color: #0000FF; } JavaScript calendar date picker We are going to discus about JavaScript calendar date picker. We have used basic JavaScript date picker functionality. We use drop-down calendar
JavaScript Date Function
JavaScript Date Function Many language provide special functions for Date, JavaScript also provides many functions for it. Given examples will illustrate the functions. JavaScript Date Function Example: <html> <head>
Validating date in javascript - Java Interview Questions
Validating date in javascript   Hi Deepak, Can u give sample code validating date in javascript using text box. thank u in advance  In what format you are going to enter the date in Text box (i.e : dd/mm
Java Swing Date Difference
Java Swing Date Difference In this tutorial, you will learn how to find the difference between two dates. Here is an example that accepts two dates from... the following method that calculates the date difference in terms of days
date_diff
date_diff date_diff alias DateTime::diff returns the difference between two DateTime objects. It returns the difference of two dates, if it exists or return... [, bool $absolute ] ) Parameters datetime - The date to compare
difference
difference  what's the difference between mysql and sql
difference
difference  difference b/w java and asp.net
Advertisements
 

 

 

DMCA.com