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
5
votes
1 answer
Conversion Hive datediff() to months
When using Hive there is the functionality to return the select datediff('date1','date2') from table value which returns the number of days between two dates.
What if I would be interested in the months between the two dates?
One option would be…

Skybrush
- 115
- 1
- 1
- 6
5
votes
7 answers
PHP get days between start-date and end-date
If I have two variables $startDate="YYYYmmdd" and $endDate="YYYYmmdd", how can I get the number of days between them please?
Thank you.

Francisc
- 77,430
- 63
- 180
- 276
5
votes
3 answers
T-SQL DateDiff - partition by "full hours ago", rather than "times minutes turned 00 since"
I have a table with timestamps, and I want to partition this table into hour-long intervals, starting at now and going backwards a couple of hours. I'm unable to get the results I need with the T-SQL DATEDIFF function, since it counts the number of…

Tomas Aschan
- 58,548
- 56
- 243
- 402
5
votes
2 answers
How do I calculate % of task's completion given start date, end date, and TODAY()
I have a gant with start date, end date, and % complete columns. By manually entering a number in the % column the bar representing the task gets shaded. What I want to do is instead of representing % completed, I want to show how much time is left…

BBDev
- 93
- 1
- 1
- 8
5
votes
1 answer
How does DATEDIFF calculate week differences in SQL Server 2005?
I would like to calculate the difference in weeks between two dates, where two dates are considered part of the same week if their preceding Sunday is the same. Ideally, I'd like to do this using DATEDIFF, instead of learning an elaborate idiom to…

eksortso
- 1,273
- 3
- 12
- 21
5
votes
3 answers
postgres '1 year' equals '360 days'?
Am wondering if anyone else has encountered this or knows information about it.
Today is November 3, 2014 and if i check whether or not November 5, 2013 is within the last year i get different answers depending on how i check: 1 year versus 365…

paulf
- 93
- 1
- 7
5
votes
4 answers
how to get the number on months between two dates in sql server 2005
I have a column in my sql server 2005 table that should hold the number of months an employee has been in service.
Since I also have the date the employee was engaged, I want the "months_In_Service" column to be a computed column.
Now if I use…

StackTrace
- 9,190
- 36
- 114
- 202
5
votes
1 answer
How can I efficiently compare two DateTimes and check if they are the same day?
I have two DateTime objects
$lastDate = $entity->getDate(); // is a DateTime with same format as $today
$today = \DateTime::createFromFormat('!Y-m-d', date('Y-m-d'));
Now I want to check, if those two dates are the same day, or if they are more…

Gottlieb Notschnabel
- 9,408
- 18
- 74
- 116
5
votes
2 answers
Between older than 30 days and less than 90days
I need to return records where there is a date older than 30days but less than 90days. so If someone bought something either 31 days ago or 89 days ago its those rows i need to return, ignoring the last 30 days and anything outside of 90days.

GPH
- 1,817
- 3
- 29
- 50
5
votes
3 answers
Date and Time Difference in Minutes
Is there any way to Display the difference between 2 different times. I currently have 2 buttons.
Sub AddButtonClick(sender As Object, e As EventArgs)
StartTime.Text = DateTime.Now.ToString()
End Sub
This generates the first timestamp
Sub…

user2602702
- 113
- 2
- 2
- 7
5
votes
3 answers
Perl: how to pretty-print time difference (duration)
How do I pretty print time duration in perl?
The only thing I could come up with so far is
my $interval = 1351521657387 - 1351515910623; # milliseconds
my $duration = DateTime::Duration->new(
seconds => POSIX::floor($interval/1000) ,
…

sds
- 58,617
- 29
- 161
- 278
5
votes
2 answers
get difference in time in HH:MM format php
how can i get this to output
HH:MM format?
$to_time = strtotime("2008-12-13 10:42:00"); <--AM
$from_time = strtotime("2008-12-14 8:21:00"); <-- PM
$stat = round(abs($to_time - $from_time) / 60,2). "min";
what i got from this is 1299 mins
but…

telexper
- 2,381
- 8
- 37
- 66
5
votes
3 answers
why does ColdFusion's DateDiff return strange/negative values?
Pulling my hair out again...
I need to calculate the difference between two dates in days. I'm doing this:
With…

frequent
- 27,643
- 59
- 181
- 333
5
votes
3 answers
Calculate DateDiff in SQL in Days:Hours:Mins:Seconds format
I am currently working an SQL script to calculate the difference between two dates which would give me the result in DD:HH:MI:SEC format.
Example:
Date 1: 7/30/12 4:00 PM
Date 2: 5/4/12 10:31 AM
And the result should be 87:05:29:00
Can you kindly…

user1423779
- 59
- 1
- 1
- 2
5
votes
1 answer
MySQL date diff iteration query - streamline query or optimize data structure
By way of introduction...
I've run into this question: Difference between 2 adjacent fields - Date - PHP MYSQL and was trying to achieve the goal, i.e iterate through dates and get diff, with pure MySQL.
Another question there (Subtracting one row…

Taz
- 3,718
- 2
- 37
- 59