javascript date difference in days.

Ads
 

javascript date difference in days.

I want to find the difference between two dates in terms of days. I am using javascript. Please help.

View Answers

May 15, 2012 at 1:31 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);

var day1=date1.getDay();
var day2=date2.getDay();
var dayDiff=(day1-day2) + (monthDiff*30);

document.write("Number of day difference : "+dayDiff);

</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, number of months by using getMonth() method and number of days by using method getDay(). Now to find date difference in days you must consider years and months too.

Ads









Related Tutorials/Questions & Answers:
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
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
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 in months
javascript date difference in months  How can I find the difference...; <head> <script type="text/javascript"> var date1=new Date(); var...; Description: In javascript whenever you write new Date() it shows the current date
javascript date comparison
= new Date(); var difference = today - date1; var days =parseInt(difference...javascript date comparison  How to compare dates and display the difference in terms of days?   <html> <head> <script
javascript questions on date
javascript questions on date  how to add some days to an existing date
Ask date difference
dates from the user and calculates the date difference in terms of days. import...; }else{ day = curdate - date + noof_days; curmonth = curmonth - 1; } if(cur...Ask date difference  Hello, I have a problem about how to calculate
How to calculate Date Difference in Java?
How to calculate Date Difference in Java?  Hi, I have two dates variable. How to calculate Date Difference in Java? Thanks   Hi, You can use the Calendar class for calculating the date difference in Java. Get data
Mysql Date Minus Days
Mysql Date Minus Days       The Tutorial cover on Mysql Date Minus Days return you the day after... an example from Mysql Date Minus Days. To understand the example, we use the select
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 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
Java subtract days from date
Java subtract days from date In this tutorial, you will learn how to subtract days 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 days from
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
Mysql Date Last 30 Days
Mysql Date Last 30 Days       Mysql is used to find out the last 30 days from current date... days'. To grasp this concept we find out the current date. The Syntax used to find
Mysql Date Add Days
Mysql Date Add Days      ... to add days to the particular date. SYNTAX:- ADDDATE(date,INTERVAL expr unit) date:-Date From which you want to add days. INTERVAL expr unit:- Number of the days
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
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
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">
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
Java Swing Date Difference
the following method that calculates the date difference in terms of days...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
Javascript calculate number of days between two dates
Javascript calculate number of days between two dates In this tutorial, you will learn how to calculate number of days between two dates.For this, you need to use the Date object  to retrieve the Date's millisecond value
JavaScript calculate age from date of birth
JavaScript calculate age from date of birth  How to calculate age from date of birth?   <html> <head> <script type="text/javascript"> function ageCount() { var date1 = new Date
JavaScript check if date is between two dates.
JavaScript check if date is between two dates.  Check if date is between two dates?   <html> <head> <title>Date before current date</title> <script type="text/javascript"> function
Java date add day
Java date add day In this tutorial, you will learn how to add days to date. Sometimes, there is a need to manipulate the date and time (like adding days to date or subtract days from date) for java applications. Here, we are going
difference
difference  difference between hashtable and hashtree
difference
difference  what's the difference between mysql and sql
difference
difference  difference b/w java and asp.net
Difference
Difference  What Is the difference between JDK & SDK

Ads