Date-difference will give difference in the number of days, months, years etc. between any two calendar dates. (synonyms in stackoverflow.com: datediff, date-diff, date-difference)
Questions tagged [date-difference]
446 questions
366
votes
14 answers
Calculate days between two Dates in Java 8
I know there are lots of questions on SO about how to get Dates in Java, but I want an example using new Java 8 Date API. I also know about the JodaTime library, but I want a method without relying on external libraries.
The function needs to be…

Marcos
- 4,827
- 3
- 20
- 28
158
votes
5 answers
Add column with number of days between dates in DataFrame pandas
I want to subtract dates in 'A' from dates in 'B' and add a new column with the difference.
df
A B
one 2014-01-01 2014-02-28
two 2014-02-03 2014-03-01
I've tried the following, but get an error when I try to include this in a…

Jase Villam
- 2,895
- 6
- 18
- 21
147
votes
28 answers
Swift days between two NSDates
I'm wondering if there is some new and awesome possibility to get the amount of days between two NSDates in Swift / the "new" Cocoa?
E.g. like in Ruby I would do:
(end_date - start_date).to_i

Linus
- 4,643
- 8
- 49
- 74
50
votes
19 answers
Android Days between two dates
I want to compare two dates for my Android application, but I got a really weird issue.
For example:
If I set the back in the past date to 127 days ago:
this.dateEvent = System.currentTimeMillis() - (127 * 24 * 3600 * 1000)
And then compare it to…

Manitoba
- 8,522
- 11
- 60
- 122
43
votes
7 answers
Find difference between two datetimes and format at Y-m-d H:i:s
I'm trying to get the difference between two datetimes and return it as a datetime. I've found examples using diff but I can't seem to get it right.
$timein = date("Y-m-d H:i:s");
$timeout = date("Y-m-d 20:00:00");
$totaltime =…

Staleyr
- 643
- 4
- 8
- 12
30
votes
8 answers
SQL Server: datediff function resulted in an overflow when using MILLISECOND
I have the following query :
select CONVERT(varchar(12), DATEADD(MILLISECOND, DateDiff(MILLISECOND, '2014-08-04 10:37:28.713','2014-11-04 08:21:17.723'), 0), 114)
When I execute this, I get the error :
"The datediff function resulted in an…

Bart Schelkens
- 1,235
- 4
- 21
- 45
29
votes
1 answer
Joda Time and Java8 Time difference
I'm looking for a solution to calculate the months between two date. I think joda or java8 time can do it. But when I compare them I found something really weird.
import java.text.ParseException;
import java.text.SimpleDateFormat;
import…

Jiaqi
- 301
- 2
- 6
26
votes
2 answers
Difference between two dates in dates using Google bigquery?
How can I get the difference in days between 2 timestamp fields in Google Big Query?
The only function I know is Datediff which only works in Legacy SQL but I'm in Standard SQL.
For example: the difference between 20180115 to 20180220 is 36 days.

Evyatar Aviram
- 261
- 1
- 3
- 3
16
votes
1 answer
How to get date difference in minutes using Hive
Below query is my sql server query and I want it to convert it into hive query:
select DATEDIFF([minute], '19000101', '2013-01-01 10:10:10')

displayname
- 317
- 1
- 5
- 15
13
votes
4 answers
C# - Calculating time difference in minutes
I have got the following code:
DateTime start = DateTime.Now;
Thread.Sleep(60000);
DateTime end = DateTime.Now;
and I would like to calculate the difference in minutes between start and end. How am I supposed to do it? For the example above, the…

P Sawicki
- 189
- 1
- 2
- 9
12
votes
4 answers
How to find the difference of two timestamps in java?
I have an ArrayList including several number of time-stamps and the aim is finding the difference of the first and the last elements of the ArrayList.
String a = ArrayList.get(0);
String b = ArrayList.get(ArrayList.size()-1);
long diff = b.getTime()…

user2052015
- 273
- 4
- 7
- 15
8
votes
13 answers
Flutter - How to find difference between two dates in years, months and days?
I'm looking for a way to use DateTime to parse two dates, to show the difference.
I want to have it on the format: "X years, Y months, Z days".
For JS, we have momentjs library and following code::
var a = moment([2015, 11, 29]);
var b =…

Jainam Jhaveri
- 1,479
- 1
- 18
- 31
8
votes
3 answers
Adding Period to startDate doesn't produce endDate
I have two LocalDates declared as following:
val startDate = LocalDate.of(2019, 10, 31) // 2019-10-31
val endDate = LocalDate.of(2019, 9, 30) // 2019-09-30
Then I calculate the period between them using Period.between function:
val period =…

Ilya
- 21,871
- 8
- 73
- 92
7
votes
6 answers
Calculate Date/Time Difference in Java considering AM/PM
I want to calculate the difference between two date/time in java using Date and Calendar classes. The format that I have is "2012-01-24 12:30:00 PM".
I have implemented my own method and also google it to work with others, but haven't getting the…

rizzz86
- 3,862
- 8
- 35
- 52
7
votes
1 answer
Java Years between 2 Instants
In Joda, we can calculate years between 2 Datetime using
Years.between(dateTime1, dateTime2);
Is there any easy way to find years between 2 instants using the java.time API instead without much logic?
ChronoUnit.YEARS.between(instant1,…

user1578872
- 7,808
- 29
- 108
- 206