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

КОМЕНТАРІ • 31

  • @AshutoshKumaryt
    @AshutoshKumaryt  Рік тому +1

    👉 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

  • @SACHINKUMAR-px8kq
    @SACHINKUMAR-px8kq Рік тому +1

    Thanks Sir , Sir Please Comeup with New SQL Projects

  • @ashuborole4079
    @ashuborole4079 7 місяців тому

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

  • @devikavaidya5897
    @devikavaidya5897 Місяць тому

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

  • @debabrataroy1777
    @debabrataroy1777 3 місяці тому

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

  • @ildodossantos3807
    @ildodossantos3807 10 місяців тому

    Many thanks

  • @user-qn5yf8bc1c
    @user-qn5yf8bc1c 5 місяців тому

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

  • @funnybhadrakia1
    @funnybhadrakia1 Рік тому

    useful concept

  • @insidehead
    @insidehead Рік тому

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

  • @akshaybomdyal
    @akshaybomdyal Рік тому

    Not working in SQL deployper also

  • @user-om6tz9us7z
    @user-om6tz9us7z 6 місяців тому

    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.

  • @hasanmougharbel8030
    @hasanmougharbel8030 Рік тому +1

    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.

    • @AshutoshKumaryt
      @AshutoshKumaryt  Рік тому

      your question sounds interesting but can you please elaborate

  • @nagasai5243
    @nagasai5243 Рік тому +2

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

  • @akshaybomdyal
    @akshaybomdyal Рік тому

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

  • @TalhaShakeelpak
    @TalhaShakeelpak Рік тому +1

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

    • @AshutoshKumaryt
      @AshutoshKumaryt  Рік тому

      You can try making something from scratch and apply the same logic

  • @arunkumar-mw9hm
    @arunkumar-mw9hm Рік тому

    Hi Ashutosh

    • @arunkumar-mw9hm
      @arunkumar-mw9hm Рік тому +1

      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

    • @AshutoshKumaryt
      @AshutoshKumaryt  Рік тому +1

      just use lead function get the timestamp in the next column , then procedd same as above it becomes the same problem now

  • @raghavmittal7112
    @raghavmittal7112 Рік тому +1

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

    • @AshutoshKumaryt
      @AshutoshKumaryt  Рік тому

      Sure you can reach out to me on instagram @ashutosh.analytics

    • @raghavmittal7112
      @raghavmittal7112 Рік тому +1

      Bro LinkedIn profile aur share krdo .. mein Instagram nhi use krta hu

    • @AshutoshKumaryt
      @AshutoshKumaryt  Рік тому

      @@raghavmittal7112 www.linkedin.com/in/ashutosh-kumar-03b420124/

    • @raghavmittal7112
      @raghavmittal7112 Рік тому +1

      Bro i had send request from the name of sparsh . Please check it once and accept the request

    • @AshutoshKumaryt
      @AshutoshKumaryt  Рік тому

      @@raghavmittal7112 my pleasure

  • @GauravMalhotra-cm1re
    @GauravMalhotra-cm1re 2 місяці тому

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