hi,
iam struggling with difference between two dates of format type dd/mm/yyyy
i need difference between two dates olddate(dd/mm/yyyy) - newdate(dd/mm/yyyy) and this should be in java script please helpme
thanking you
3 1794 ak1dnar 1,584
Recognized Expert Top Contributor
If you need it from JAVASCRIPT ask the question in this forum
Moving from Php forum.
phvfl 173
Recognized Expert New Member
Hi,
The function that you would be looking to use would be the setFullYear() function of the Date object in javascript. setFullYear() sets the date value, taking three variables (four digit year, month and day). The month is base 0 so Janary would be 0, for example: -
var date1 = new Date();
-
date1.setFullYear(2007,0,1);
-
would set date1 to the 1st January 2007. The dates are actually stored as integers and their base value is the number of milliseconds since 1st January 1970, so if you subtract one date from another you would get the difference in time in milliseconds. Once you have this it would be simple arithmetics to convert the difference into whatever unit of time that you want.
If you are still having difficulties please post back your attempted code to look at.
- function daysbetween(s1,s2){
-
/*
-
First, convert your strings to javascript Date objects.
-
Reverse the order from dd/mm/yyyy to yyyy/mm/dd,
-
and subtract 1 from the month field
-
(months are 0-based, january is 0)
-
*/
-
-
var d1= s1.split(/\W+/).reverse();
-
var d2= s2.split(/\W+/).reverse();
-
-
d1= new Date(d1[0],d1[1]-1,d1[2]);
-
d2= new Date(d2[0],d2[1]-1,d2[2]);
-
-
//Now you can subtract the two dates and return the difference in days
-
-
return Math.floor((d2-d1)/8.64e7)+ ' d
-
}
-
// Test Case
-
-
var s1= '06/09/2007';
-
var s2= '25/12/2007';
-
alert(daysbetween(s1,s2))
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Hans Gruber |
last post by:
Hi all,
I have been struggling with a problem all day, I have been unable to come
up with a working solution.
I want to write a function which takes 2 unix timestamps and calculates
the difference. I want it to return the difference in years, months, days,
hours, minutes and seconds (a complete summary). Keeping into account of
course that these are 2 real dates, I dont want it to work with 30.475 as
an average number of days in a...
|
by: riki |
last post by:
hello,
i need to calculate num of days between 2 dates...
i get separate parts of dates from html form, then i need to "make" begining
and ending date and calculate difference between them...
something like this, in sybase:
DAYS(YMD(?YEAR?,?MONTH?,?DAY?), YMD(?YEAR1?,?MONTH1?,?DAY1?))
thnx
|
by: Scott |
last post by:
Hi All
I have an application that has a start date and a finish date I need to
calculate the number of days from the start date to the end date and then
display this in a read only text box... How might I code this?...
Regards
Scott
|
by: Carl |
last post by:
Hi,
I have a query that produces an output similar to the sample shown
below. These records are based on certain criteria and a date range
selected from a form. I need to create some kind of calcualtion or
record manipulation to do the following:
I need to subtract dates from one another, for example for ID 1 I want
to find the difference between 24-Jun-04 and 25-Jan-06 for the 2
applications for Person1.
|
by: Yotam |
last post by:
Hi,
I need some help with JS. I will be grateful, if you can help me out.
I have two date fields (check in, check out) and "number of days"
field.
I want the script to calculate automatically the difference.
For example: I have defaults dates, and I want the script to put the
difference in "number of days" field. And if the user will change the
date, the number of days will change automatically.
| |
by: Julius |
last post by:
Hej dudes,
I need to calc the difference between two timestamps / dates ...
For example what i need to calculate:
Date 1: 2007.11.06 - 20:13:04
Date 2: 2007.11.07 - 21:13:04
Difference: 1 day, 1hour
|
by: krishnakant Mane |
last post by:
hello,
I am strangely confused with a date calculation problem.
the point is that I want to calculate difference in two dates in days.
there are two aspects to this problem.
firstly, I can't get a way to convert a string like "1/2/2005" in a
genuan date object which is needed for calculation.
now once this is done I will create a another date object with
today = datetime.datetime.now()
and then see the difference between this today and...
|
by: ncsthbell |
last post by:
I am having problems getting the end date to calculate correctly.
I start with Quarter '03/02', (YY/QTR), for this it means it is for the 2nd qtr of 2003. My goal is to get the begin & end dates for each 'month' in the quarter, hence, I want to calculate the begin & end of the month dates for April, May & June 2003 :
so my starting point is:
firstMonthBegin = vcBegMM & "/" & vcBegDD & "/" & vcBegYY
firstMonthEnd = vcEndMM &...
|
by: mfaisalwarraich |
last post by:
Hi everybody. I have some problem while calculating time. i have employees who are working on hourly basis. i want to calculate the time. for example if an employee start working at 11:00pm (10-November-2008) and finish his job at 8:00am (11-November-2008) then how i can calculate the time between two different dates? i used dateDiffer method but it only displays the time difference between one date. please tell me how i can do this. thank you....
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |