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
0
votes
1 answer
Difference between dates in different rows
Hy
my problem is, that I need the average time between a chargebegin & chargeend row (timestampserver) grouped by stationname and connectornumber and day.
The main problem is, that i can not use a Max oder Min function because I have the same…

user2067767
- 3
- 1
0
votes
1 answer
mysql assignment within function
I have a history table with a DATETIME column. Is it not possible to assign a variable within a DATEDIFF function? The following statement:
SET @LASTDATETIME='2000-01-01 00:00:00';
SELECT DATETIME, @LASTDATETIME, TIMEDIFF(DATETIME,…
0
votes
2 answers
TSQL Calculating daily sum across records with overlapping date ranges
I have 3 tables, 1 (PortfolioInstrument) holds instruments (Instrument) held in a portoflio with the holding (Holding) across a date range (DateAdded, DateRemoved).
Another (Price) holds daily (TradeDate) closing prices ([Close]) for each instrument…

Olddave
- 397
- 1
- 2
- 12
0
votes
2 answers
SQL Query for all Records at Least 30 days old
I am trying to track user data for when users log in to an application. What I am trying to pull from my query (below) is all users who have not logged in for the past 30 days or more. However, it is pulling in users who have logged in quite…

Nicholas Anderson
- 583
- 8
- 19
0
votes
3 answers
datediff causing error in php
I have sql statement that works great in mysql, where I'm am using datediff. When I try to use it in php, I get an "mysql_fetch_arrary() expects parameter 1 to be a resource, boolean given in"
This the statement is...
$result = mysql_query("select…

terrorpup
- 1
- 1
0
votes
2 answers
order by DATEDIFF gives Conversion failed error
I'm editing a query i build in ms sql.
I need to order the items on date, but that gives an error.
locations_aanvang gives 2012-08-12(yyyy-mm-dd). so i extend it to 2012-08-12 00:00:00 +1:00 for EST time.
So to order the i need to convert it to unix…

Bram Hammer
- 363
- 4
- 21
0
votes
1 answer
DateDiff gives A constant expression was encountered in the ORDER BY
I want to edit a query but I'm stuck. I want to order by a date (originally '2012-12-28') but i read it must be converted to unix timestamp to do that.
I don't know if i am doing it wrong so please help me!
The weird thing is when i execute the…

Bram Hammer
- 363
- 4
- 21
0
votes
0 answers
Comparing dates in a OLE source of an SSIS package
I am trying to create an SSIS package which pulls a set of records from the database by checking a date field (MODIFYDATE) in the table against a package variable (User::LastUpdate). Records where MODIFYDATE is equal to or after LastUpdate get…

Hypersapien
- 617
- 2
- 8
- 23
0
votes
3 answers
query get the current date with condition
I need to get the date from date table minus 3 days (business days to be specific). Below is the structure:
date business day
1/1/13 Y
1/2/13 N
1/3/13 Y
1/4/13 Y
1/5/13…

user1993970
- 3
- 1
- 2
0
votes
2 answers
IS DATEDIFF function allows query
I want to write a query using DATEDIFF Function in SQL.
When I try
SELECT AVG(DATEDIFF(hh,raise_date,(select min(added_note) from t_case_note) ))
FROM mytable
I get the error message
Cannot perform an aggregate function on an expression containing…

SanDeep KumAr
- 29
- 2
0
votes
1 answer
SQL query-How to calcucate average time difference from two dates in format : 5 days 13 hours
I wrote SQL expression in format:
select date1,date2,
cast ( Floor ( timestampdiff (4, char ( timestamp (DATE2)-
timestamp (DATE1)))/1440) as char (3))||'days' ||' '
|| cast ( Floor ( Mod ( timestampdiff (4, char( timestamp…

Stefke
- 141
- 8
- 19
0
votes
4 answers
Using datediff in sql jdbc query
I'm attempting to create a JDBC query with the following statement
String query = "SELECT COLUMN1,DATECOLUMN2 FROM tableName +
"where datediff(d,DATECOLUMN2,getdate()) <= 1";
st = conn1.createStatement();
rs = st.executeQuery(query); …

Marquis Blount
- 7,585
- 8
- 43
- 67
0
votes
2 answers
Select previous 3 months
I am looking to select tickets from the previous 3 months. By calculate the previous 3 months.
I saw this post:
https://stackoverflow.com/questions/7268896/calculate-3-month-period-using-mysql
But it does not seem to work.
Here is my query
select…

Greg
- 31
- 7
0
votes
1 answer
DateDiff and regional settings
I've got a VBscript that runs on devices placed all over the world and therefore uses various regional settings.
A part of my script is calculating the difference between 2 dates, but I can't get that working with a consistent result.
An…

Michael G
- 39
- 1
- 8
0
votes
3 answers
sql telling how many days have passed(datediff)
I'm working on a project where I want to display data after 3 days have passed.
What I'm having an issue with is getting the current date dynamically in php/sql. I'm aware of how to get the current date in php, but I dont know how to compare that…

user1946499
- 11
- 1