How to calculate difference between two timestamps in SQL | Datediff in sql | Ashutosh Kumar

preview_player
Показать описание
Sql one of the most important language asked in most of the analytics interviews, in this video i am discussing about a very important concept in sql which is calculating difference between two timestamp in terms of hours , minutes and seconds using datediff function in sql. So do watch the video till the very end.

👉 Query -

drop table if exists details;
CREATE TABLE details(Timing1 TIME, Timing2 TIME);

INSERT INTO details(Timing1,Timing2)
VALUES('10:50:00','12:30:00'),
('12:30:00','13:52:00'),
('05:45:00','09:00:00');

select * from details;

👉 Complete playlist on Sql Interview questions and answers

---------------------------------------------------------------------------------------------------------------------
Check out some more relevant content here

👉 How to Learn SQL

👉 How to become a business analyst complete roadmap-

👉 How to become a data analyst complete roadmap-

👉 Top 3 you tube channels to learn sql for free for beginners

👉 Rank ,Dense Rank, Row Number in sql -

👉 Cross join in sql

👉 union join in sql

👉 left join in sql

👉 Right join in sql

👉 Inner join in sql

👉 Introduction to tables and databases in sql -

👉 Aggregate Function in sql

👉 Functions in sql-

👉 String Function in sql

👉 CRUD operations in sql

👉 Autoincrement in sql

👉 Primary Key in sql-

👉 Null and Default values in sql-

👉 Data types in sql-

____________________________________________________________________

_______________________________________________________________________
Connect with me

_____________________________________________________________________

Comment down if you have any doubts
Please leave a LIKE 👍 and SUBSCRIBE ❤️ to my channel to receive more amazing content in data analytics and data science.

_____________________________________________________________________

🏷️ Tags

sql,
sql for data science,
sql for data analytics,
sql practise questions,
sql practise questions and solutions,
sql tutorials for beginners,
sql problems for data engineers,
ashutosh,
ashutosh kumar,
ashutosh kumar analytics,
sql problems easy,
sql problem medium,
sql problems hard,
sql window functions,
sql advanced questions,
rank functions in sql,
lag lead in sql,
sql interview questions and answers,
sql interview questions,
sql questions asked in interviews,
hackerrank sql solutions,
hackerearth sql solutions,
leetcode sql solution

🏷️HashTags

#sql #interviews #questions #solutions
Рекомендации по теме
Комментарии
Автор

👉 SQL Portfolio Project Indian Census- Part 1
👉 Advanced Sql Concepts Complete Playlist

AshutoshKumaryt
Автор

Hi I am working in oracle apex but their datediff is not working can you suggest any another please

ashuborole
Автор

hi brother i tried this method but im getting false output can you help me with my code?

qnyfbcc
Автор

Thanks Sir, Sir Please Comeup with New SQL Projects

SACHINKUMAR-pxkq
Автор

Thank u for this video, but i want to calculate sum of different time stamps can u please help me

devikavaidya
Автор

Time difference is negative when Timing1=23:58:00 and Timing2=00:13:00. How to fix it?

debabrataroy
Автор

Ticket create date : 05/01/2024 09:30 AM, Ticket closing date: 07/01/2024 12:30 PM, I want the total duration but after 09 pm to 09 am i dont want to count the hours, whats the excel formula. please help.

omtzusz
Автор

Pls tell me how to find the time period of the given dataset

nagasai
Автор

Hey there, glad to meet again.
I learned about timestamp as a date data type.
My question is, if i where to record timestamps of every record entered into the database. Would the sql server generate two identical timestamps given the records where run simultaneously..is that case a hypothetical one or would it happen?
Thanks for taking care of this.

hasanmougharbel
Автор

Bro it is not working in toad application, what is the function datediff in toad

akshaybomdyal
Автор

select *, timediff(lead(time) over(partition by `train id` order by time), time)
as "duration till next station" from trains;

insidehead
Автор

Bro tumhare se personal contact kaise ho skta h .. want to make you mentor in my data science journey you are teaching great stuff

raghavmittal
Автор

Hi, how to convert this in time format? I'm using convert() function but it is not working.

TalhaShakeelpak
Автор

Much easier way :-

SELECT
CONCAT(
HOUR(TIMEDIFF(Timing2, Timing1)), ' hours ',
MINUTE(TIMEDIFF(Timing2, Timing1)), ' minutes ',
SECOND(TIMEDIFF(Timing2, Timing1)), ' seconds'
) AS TimeDifference
FROM Time;

GauravMalhotra-cmre