Search
 
SCRIPT & CODE EXAMPLE
 

SQL

date diff sql

SELECT DATEDIFF(year, '2017/08/25', '2011/08/25') AS DateDiff;
Comment

how to get the date diff on once field in sql server

SELECT t1.OrderNo,DATEDIFF(day,t1.LoadedStartDate,t2.LoadedStartDate)
FROM UnnamedTableFromQuestion t1
       INNER JOIN
     UnnamedTableFromQuestion t2
       on
         t1.OrderNo = t2.OrderNo
WHERE t1.OpNo = 1 and
      t2.OpNo = 4
      
////////////////////////////////////////////////////////////////

select cur.unique_id_field, cur.seq_no, cur.date_created ,

  datediff(second, prv.date_created, cur.date_created) as diff_in_seconds

from yourtable as cur

  join yourtable as prv

    on cur.seq_no = prv.seq_no + 1;
Comment

how to get the date diff of 2 dates in the same fieldin sql server

WITH Partitioned AS(	SELECT *, ROW_NUMBER() OVER (PARTITION BY cu_id, date ORDER BY cu_id, date) AS RowNumber	FROM @Table) SELECT 	*,	CASE 		WHEN RowNumber > 1 THEN 0		ELSE COALESCE(DATEDIFF(DAY, (SELECT MAX(date) FROM @Table WHERE date < a.date AND cu_id = a.cu_id), a.date), 0)	END AS Days_betweenFROM Partitioned a
Comment

PREVIOUS NEXT
Code Example
Sql :: truncate function in sql oracle 
Sql :: SQL Server rename foreign key constraint 
Sql :: how to change column name in sql 
Sql :: command line mysql xampp 
Sql :: replace string value in sql 
Sql :: postgres set column equal to another 
Sql :: inner join sql oracle 
Sql :: drop df constraint sql server 
Sql :: mysql where value is null 
Sql :: sql server list locks 
Sql :: oracle apex debug mode 
Sql :: how to extract year from date in sql 
Sql :: phpmyadmin password root 
Sql :: sql waitfor 
Sql :: create table employees oracle 
Sql :: sql compare strings 
Sql :: create index mysql 
Sql :: postgresql get today 
Sql :: mysql full outer join 
Sql :: sql current date 
Sql :: oracle add time to date 
Sql :: mysql delete duplicate rows but keep one 
Sql :: mysql two column combination unique 
Sql :: mysql find duplicates in same table 
Sql :: sql datetime format 
Sql :: How to pass password to mysql command line 
Sql :: sql email Regex 
Sql :: avg sql 
Sql :: soql last week 
Sql :: mysql get last 2 month data 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =