Date-difference will give difference in the number of days, months, years etc. between any two calendar dates. Not defined by ISO/ANSI SQL, but several vendors have similar implementations.
Questions tagged [datediff]
1599 questions
23
votes
7 answers
How to get a DateDiff-Value in milliseconds in VBA (Excel)?
I need to calculate the difference between two timestamps in milliseconds.
Unfortunately, the DateDiff-function of VBA does not offer this precision.
Are there any workarounds?

Florian
- 930
- 2
- 11
- 19
23
votes
3 answers
SQL Datediff - find datediff between rows
I would like to query a database using sql to show the difference in time between id 1,2,3 and so on. basically it will compare the row below it for all records. any help would be appreciated.
IDCODE DATE TIME DIFFERENCE (MINS)
1 …

Tyrone2011
- 239
- 1
- 2
- 3
22
votes
3 answers
DATEDIFF in SPARK SQl
I am new to Spark SQL. We are migrating data from SQL server to Databricks.
I am using SPARK SQL . Can you please suggest how to achieve below functionality in SPARK sql for the below datefunctions. I can see datediff gives only days in spark…

SQLGirl
- 287
- 2
- 3
- 6
21
votes
2 answers
SQL Server 2005: how to subtract 6 month
I have a date, suppose today date
declare @d datetime
set @d = '20101014'
I need
select @d -
where is the real number of days that contains last six month, beginning from @d.

skaeff
- 753
- 2
- 13
- 25
19
votes
2 answers
date_diff() expects parameter 1 to be DateTimeInterface, string given
They have the same format:
$date_expire = '2014-08-06 00:00:00';
$date1 = date("Y-m-d G:i:s");
$date2 = date_create($date_expire);
$diff = date_diff($date1, $date2); //this line makes error.
But I am getting this error:
date_diff() expects…

ShelðÔn Alag
- 367
- 2
- 3
- 12
16
votes
1 answer
Athena DateDiff
I am trying to do what I think is a simple date diff function but for some reason, my unit value is being read as a column ("dd") so I keep getting a column cannot be resolved error
I am using AWS Athena
My code is this
SELECT "reservations"."id"…

JoeD
- 223
- 1
- 3
- 5
16
votes
2 answers
PHP Difference in months between two dates?
Possible Duplicate:
How to calculate the difference between two dates using PHP?
Date Difference in php?
I have two dates in a variable like
$fdate = "2011-09-01"
$ldate = "2012-06-06"
Now I need the difference in months between them.
For…

Jaiff
- 497
- 2
- 5
- 17
15
votes
5 answers
How to get the difference in minutes between two dates in Microsoft Excel?
I am doing some work in Excel and am running into a bit of a problem. The instruments I am working with save the date and the time of the measurements and I can read this data into Excel with the following format:
A B
1 Date: …

Linux Rules
- 473
- 3
- 9
- 17
14
votes
3 answers
Is it possible to set start of week for T-SQL DATEDIFF function?
I use DATEDIFF function to filter records added this week only:
DATEDIFF(week, DateCreated, GETDATE()) = 0
and I noticed what it's assumed what week starts on Sunday. But in my case I would prefer to set start of week on Monday. Is it possible…

Alexander Prokofyev
- 33,874
- 33
- 95
- 118
13
votes
2 answers
DateDiff return different result for each timezones
I have problem with PHP DateDiff, i dont understand why each timezone returns different results, for example in this case Prague return 0 month, and US return 1 month.
What do this difference and how i return 1 month (instead 30 days, when i adding…

patie
- 1,074
- 1
- 10
- 18
13
votes
1 answer
Datediff performance
I have a number of days variable which I want to compare against a datetime column (senddate).
I'm currently doing this:
DECLARE @RunDate datetime = '2013-01-01'
DECLARE @CalculationInterval int = 10
DELETE
FROM TableA
WHERE datediff(dd, senddate,…

Murtaza Mandvi
- 10,708
- 23
- 74
- 109
12
votes
7 answers
Java Calendar: Getting Difference Between Two Dates/Times - Off by One
I have seen many questions and answers on this topic, but none addressed my particular problem. I extended the java Calendar class (standard--no third party libraries), and needed to find the difference in days between two arbitrary…

SMBiggs
- 11,034
- 6
- 68
- 83
11
votes
2 answers
Mysql Datediff query
I need to get the result from the table, which the date should be difference of 5 from the current date.
ie., specific_date column is present in my table. The format of the date is YYYY-MM-DD.
I need the query something like,
SELECT * FROM…

sathish
- 800
- 1
- 8
- 19
11
votes
2 answers
How to calculate time difference between two dates using LocalDateTime in Java 8?
There are numerous answers given but I am unable to find compatible with my situation. I need to find difference of 8 hours in time as well as on date change too. Like if time is greater then 8 hours then do not execute something .
Do we have any…

Harpreet
- 186
- 1
- 1
- 10
11
votes
5 answers
How to calculate difference of two string dates in days using PHP?
I have two date variables:
$dnow = "2016-12-1";
$dafter = "2016-12-11";
I want to calculate the difference of this two dates which are in string format so how do I calculate?
I used
date_diff($object, $object2)
but it expecting two date object,…

Abhijit Kumbhar
- 923
- 3
- 23
- 49