How to calculate difference between two timestamps in SQL | Datediff in sql | Ashutosh Kumar
Вставка
- Опубліковано 12 сер 2022
- 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
• HackerRank SQL problem...
---------------------------------------------------------------------------------------------------------------------
Check out some more relevant content here
👉 How to Learn SQL
• How to learn sql for b...
👉 How to become a business analyst complete roadmap-
• Business Analyst Compl...
👉 How to become a data analyst complete roadmap-
• Data Analyst Complete ...
👉 Top 3 you tube channels to learn sql for free for beginners
• Video
👉 Rank ,Dense Rank, Row Number in sql -
• RANK - DENSE RANK - RO...
👉 Cross join in sql
• CROSS JOIN SQL
👉 union join in sql
• UNION IN SQL
👉 left join in sql
• LEFT JOIN IN SQL
👉 Right join in sql
• RIGHT JOIN IN SQL
👉 Inner join in sql
• INNER JOIN IN SQL
👉 Introduction to tables and databases in sql -
• INTRO TO TABLES AND DA...
👉 Aggregate Function in sql
• AGGREGATE FUNCTION IN SQL
👉 Functions in sql-
• IMPORTANT FUNCTIONS IN...
👉 String Function in sql
• STRING FUNCTIONS IN SQL
👉 CRUD operations in sql
• CREATE- READ- UPDATE-D...
👉 Autoincrement in sql
• Auto Increment in SQL ...
👉 Primary Key in sql-
• PRIMARY KEYS IN SQL - SQL
👉 Null and Default values in sql-
• NULL AND DEFAULT VALUE...
👉 Data types in sql-
• Data types in Sql - SQL
____________________________________________________________________
Fill the form below to subscribe yourself to the analytics jobs mailing list to receive regular job opening updates - docs.google.com/forms/d/e/1FA...
Why you should definitely fill the analytics job updates google form - • Job Openings into busi...
_______________________________________________________________________
Connect with me
📸Instagram - / ashutosh.analytics
💻Linkedin- / ashutoszh
_____________________________________________________________________
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
ua-cam.com/video/I3YvjFfn478/v-deo.html
👉 Advanced Sql Concepts Complete Playlist
ua-cam.com/play/PLbTF1OfX62c3RQ_ZFfyNBWVPdz_OWTMLG.html
Thanks Sir , Sir Please Comeup with New SQL Projects
Hi I am working in oracle apex but their datediff is not working can you suggest any another please
Thank u for this video, but i want to calculate sum of different time stamps can u please help me
Time difference is negative when Timing1=23:58:00 and Timing2=00:13:00. How to fix it?
Many thanks
Thanks
hi brother i tried this method but im getting false output can you help me with my code?
useful concept
Thanks
select *, timediff(lead(time) over(partition by `train id` order by time),time)
as "duration till next station" from trains;
Not working in SQL deployper also
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.
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.
your question sounds interesting but can you please elaborate
Pls tell me how to find the time period of the given dataset
pls elaborate
Bro it is not working in toad application, what is the function datediff in toad
just check on google bro
Hi, how to convert this in time format? I'm using convert() function but it is not working.
You can try making something from scratch and apply the same logic
Hi Ashutosh
How we can extract time difference for for one Column.
for example
Timing1 has 3 records
I need to calculate time difference then cumulative those values
Can you please give your mobile number
I can pay money for this requirement
just use lead function get the timestamp in the next column , then procedd same as above it becomes the same problem now
Bro tumhare se personal contact kaise ho skta h .. want to make you mentor in my data science journey you are teaching great stuff
Sure you can reach out to me on instagram @ashutosh.analytics
Bro LinkedIn profile aur share krdo .. mein Instagram nhi use krta hu
@@raghavmittal7112 www.linkedin.com/in/ashutosh-kumar-03b420124/
Bro i had send request from the name of sparsh . Please check it once and accept the request
@@raghavmittal7112 my pleasure
Much easier way :-
SELECT
CONCAT(
HOUR(TIMEDIFF(Timing2, Timing1)), ' hours ',
MINUTE(TIMEDIFF(Timing2, Timing1)), ' minutes ',
SECOND(TIMEDIFF(Timing2, Timing1)), ' seconds'
) AS TimeDifference
FROM Time;