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
11
votes
4 answers
Calculating difference of dates In Postgresql
I'm trying to find out the time between certain fields in my tables. However cause I'm using Postgresql :(( I can't use the DATEDIFF function. I can't find any clear guides/ tutorials on the net which shows how to do a similar thing in Postgres so I…

Jimmy
- 817
- 4
- 13
- 19
10
votes
1 answer
SQLite: express the difference as days, hours, minutes between two given dates
I am trying to express the difference of two given dates in days, hours, and minutes (like 1 day, 6 hours, 17 minutes.) as SQLite query output. I have entryin and entryout as datetime fields in a SQLitedatabase. I tried all combinations of julianday…

Srikanth S
- 1,717
- 5
- 16
- 21
10
votes
1 answer
Is timestampdiff() in MySQL equivalent to datediff() in SQL Server?
I am working on migrating functions from SQL Server 2000 to MySQL.
The following statement executed in SQL Server 2000, gives the output as 109.
SELECT DATEDIFF(wk,'2012-09-01','2014-10-01') AS NoOfWeekends1
The equivalent query of in mysql uses…

user2905792
- 121
- 1
- 1
- 7
10
votes
1 answer
DATEDIFF() Parameter Issue
The old DATEDIFF() allowed users to use 3 parameters, and I was trying to do this so I could get hours out of my DATEDIFF rather than days, (I'm trying to show hours since a post). In my database I'm using a TIMESTAMP and this line of code to pull a…

pcort
- 419
- 1
- 6
- 19
10
votes
4 answers
Number of days between current date and date field
I have this problem if anyone can help.
There is a field (date) in my table (table1) that is a date in the format 3/31/1988 (M/D/y), and my necessity is to define how many days have passed since that date.
I have tried to give this…

user1951561
- 119
- 1
- 1
- 9
9
votes
1 answer
How to calculate elapsed time in seconds in VBA?
I have 2 strings, strStartTime and strEndTime.
strStartTime = "12:32:54"
strEndTime = "12:33:05"
I want to find out how many seconds elapsed between strStartTime and strEndTime so I did this:
Dim dtDuration as date
dtDuration = DateDiff("s",…

MrPatterns
- 4,184
- 27
- 65
- 85
9
votes
3 answers
How to find the difference between dates in VBA
I am trying to find out the difference between the system date and the date stored in the worksheet. If the difference between them is > 30 days, the result is true, else the result is false
Dim result as boolean
Dim sDate as string
sDate = Date
if…

Ank
- 6,040
- 22
- 67
- 100
9
votes
3 answers
Calculate month difference in Joda Time
At the 4th line of code (ignore whitespace & comments) and beyond I'm calculating the month difference between 2 dates. This works, but looks a bit hacky. Is there a better way?
int handleAllowance(LocalDate today) {
int allowance =…

Bart van Heukelom
- 43,244
- 59
- 186
- 301
9
votes
4 answers
What is the recommended way of doing date arithmetics in Perl?
What is the recommended way of doing date arithmetics in Perl?
Say for example that I want to know the date three days ago from today (where today = 2010-10-17 and today - 3 days = 2010-10-13). How would you do that in Perl?

knorv
- 49,059
- 74
- 210
- 294
9
votes
4 answers
Javascript DateDiff
I am having a problem with the DateDiff function. I am trying to figure out the Difference between two dates/times. I have read this posting (What's the best way to calculate date difference in Javascript) and I also looked at this tutorial…

Frank G.
- 1,519
- 7
- 25
- 43
9
votes
4 answers
How to convert given number of days to years, months and days in MySQL?
I am trying to get the date and time duration between the Loan taken and Paid date. I used the PHP date and time functions, but it is not always accurate. How can I do this accurately in MySQL?
Let assume two dates, The Loan taken…

Madan Sapkota
- 25,047
- 11
- 113
- 117
9
votes
4 answers
DateDiff years into decimals
I have two dates in which i would like to find the number of years between them, however i would need to show the value to two decimal places. I have tried the following but i always get a value returned of 0 as all of my dates do not cover a whole…

chrissy p
- 823
- 2
- 20
- 46
8
votes
1 answer
Python Pyspark: Filter for 1 Day Before Current Date Using F.current_date()
I want to filter my data set for all the dates before a certain date. Specifically 1 day before the current date.
I tried the code below:
df = df.filter(F.col('date') <= F.current_date() - 1)
But I got the following error:
u"cannot resolve…

PineNuts0
- 4,740
- 21
- 67
- 112
8
votes
1 answer
Trigger with a RAISERROR and ELSE case issue
I am trying to make a bit of code that takes in 2 separate columns, a month and a year. From there I want it to see if those numbers entered have already passed or not. If they have passed, cause an error to pass and stop the transaction. Otherwise,…

MikeyZ
- 105
- 1
- 1
- 6
8
votes
4 answers
SSRS 2008 Datediff for Working Days
I have seen this question asked a lot and I cannot seem to find one clear answer about
"how to calculate business days only between two dates?"
The expression below will give me the total days but I am looking to exclude Saturday and…

Lance
- 125
- 1
- 3
- 7