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
4
votes
5 answers
Count days between two dates, excluding weekends (MySQL only)
I need to calculate the difference (in days) between two dates in MySQL excluding weekends (Saturday and Sunday). That is, the difference in days minus the number of Saturday and Sunday in between.
At the moment, I simply count the days…

lorenzo-s
- 16,603
- 15
- 54
- 86
4
votes
3 answers
Exact c# result of sql datediff
I'm trying to get the number of days (calculated byu datediff) in sql and the number of days in c# (calculated by DateTime.now.Substract) to be the same, but they return different results....
//returns 0
int reso =…

M.R.
- 4,737
- 3
- 37
- 81
4
votes
0 answers
Luxon diff DST issue
I am trying to calculate time difference given a start datetime and end datetime. I have 2 date objects to calculate the time difference. The issue is when the dates span across a DST day (eg:- Nov 7th).
start datetime = Nov 6th, 16:30
end datetime…

PackedUp
- 369
- 5
- 16
4
votes
1 answer
Power BI - DAX Measure to calculate churned and reactivated customers in the current period. Incorrect total
Below is a simplified version of the data. Daily transaction list for customer ID
SalesData =
DATATABLE (
"Customer ID", INTEGER,
"Date", DATETIME,
"Amount", INTEGER,
{
{ 101245, "2019/04/07", 500 },
{ 101245,…

Adni
- 133
- 1
- 11
4
votes
2 answers
Finding the DATEDIFF between two columns and creating its own column
Trying to find the DATEDIFF between two dates and display it as it's own column.
Here are my current columns:
currentcolumns
And here is what I need:
needed
Here is the code I have been running with error:
SELECT orderNumber,…

Shawn Benson
- 137
- 1
- 7
4
votes
3 answers
DateDiff in MySQL with same column
I have a table 'orders' that looks like this:
+---------------+--------------+------------+
| customer_name | order_number | date |
+---------------+--------------+------------+
| jack | 1 | 2018-01-01 |
| jack | …

krthkskmr
- 461
- 5
- 22
4
votes
2 answers
SQL Server LAG() function to calculate differences between rows
I'm new in SQL Server and I've got some doubts about the lag() function.
I have to calculate the average distance (in days) between two user's activities. Then, I have to GROUP BY all the users, calculate all the date differences between rows for…
user9863243
4
votes
2 answers
pyspark: hours diff between two dates columns
I would like to calculate number of hours between two date columns in pyspark.
Could only find how to calculate number of days between the dates.
dfs_4.show()
+--------------------+--------------------+
| request_time| …

Adi Milrad
- 135
- 3
- 9
4
votes
3 answers
MySQL Dates between Dates
I am wondering if there is a way, in MySQL 4.1+, to query the specific dates between date ranges in my records?
For a quick example, I have two records with datetime ranges, like
ID | Activity | Start Date | End Date
1 Closed …

Jordan
- 187
- 3
- 7
4
votes
1 answer
Pyspark: Difference between two Dates (Cast TimestampType, Datediff)
There is a table with incidents and a specific timestamp. I struggle to calculate the number of days passed using the Pyspark 2.0 API. I managed to do the same thing when the timestamp followed another format (yyyy-mm-dd)
…

Niklas Brauer
- 67
- 1
- 2
- 7
4
votes
2 answers
Get the time difference between the first and last row
My table structure is like this
id date Time userid
17 2017-01-22 05:08:09.0000000 836232017
16 2017-01-22 05:08:05.0000000 836232017
11 2017-01-22 05:06:40.0000000 836232017
10 2017-01-22 05:06:38.0000000 …

Deepu T
- 724
- 7
- 20
4
votes
2 answers
Get calendar days between two dates
The DateDiff function reports Day Intervals on a 24 hour basis, which provides an odd result when asking how many days ago something happened when the time of day changes.
For example, if I want to get the number of days since yesterday afternoon,…

KyleMit
- 30,350
- 66
- 462
- 664
4
votes
2 answers
django: datediff sql queries?
I'm trying to do the equivalent of the following SQL in Django:
SELECT * FROM applicant WHERE date_out - date_in >= 1 AND date_out - date_in <= 6
I can do this as a RAW sql query, but this is becoming frustrating in dealing with a RawQuerySet…

tufelkinder
- 1,176
- 1
- 15
- 37
4
votes
3 answers
pandas: function equivalent to SQL's datediff()?
Is there an equivalent to SQL's datediff function in Python's pandas?
The answer to this question:
Add column with number of days between dates in DataFrame pandas
explains how to calculate the difference in days. For example:
>>>…

Pythonista anonymous
- 8,140
- 20
- 70
- 112
4
votes
5 answers
Difference in Days between two Java dates?
I want to get the difference between two Java Date objects. I've used Joda-Time library. But the problem is that I'm getting the Days greater difference than that of actual day difference.
Here's my code snippet:
DateFormat formatter = new…

Venkat
- 2,604
- 6
- 26
- 36