Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8265161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:42:10+00:00 2026-06-08T04:42:10+00:00

I want to make a function call that hase efect in SQLite like TIMEDIFF

  • 0

I want to make a function call that hase efect in SQLite like TIMEDIFF in MySQL.

I made this:

select strftime('%s','2012-01-01 12:00:00') - strftime('%s','2004-01-01 02:34:56')

but this is just the number of seconds. So how can i make a str like %Y-%m-%d %H:%M:%S where %H:%M:%S is the hours, minutes and seconds difference, and when it is bigger then 24 hours then %d will show how much dais it is and so on with %Y and %m.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T04:42:12+00:00Added an answer on June 8, 2026 at 4:42 am

    You cannot represent a time difference with %Y-%m-%d ..., at least not as a date format. How would you express less than a day of difference? (0000-00-00 ... is not a valid date). Also, what would a month be? 30 days? 31 days? 23423432 days?

    I suggest you keep your difference in seconds, and when presenting it you adapt it as necessary.

    On the other hand, if you really want to do as you asked, here’s one way:

    sqlite> select datetime(strftime('%s','2012-01-01 12:00:00') 
                   - strftime('%s','2004-01-01 02:34:56') - 62167305600, 'unixepoch');
    0007-12-31 09:25:04
    

    Even if I feel the downvote by the OP wasn’t justified, I can’t stop myself from explaining why what I mentioned above as clearly not a very good option returns “incorrect” results when the time difference is less than 1 day: the reason is implied in what I wrote above: there is no such date as 0000-00-00 ... so instead the datetime returned goes in negative territory: -001-12-31 ...

    Here’s a way to obtain 438:53:45, but it’s quite involved:

    earlier date: d1
    later date: d2
    
    select 
        cast(
            (strftime('%s', d2) - strftime('%s', d1)) / 86400 * 24 
                 + cast(strftime("%H", time(strftime('%s', d2) 
                        - strftime('%s', d1), 'unixepoch')) 
                   as int) 
        as text) 
        || ":" 
        ||  substr(time(strftime('%s', d2) - strftime('%s', d1), 'unixepoch'), 4);
    

    Example:

    d1 = '2004-01-01 02:34:56'
    d2 = '2012-01-01 12:00:00'
    
    sqlite> select cast((strftime('%s','2012-01-01 12:00:00') - strftime('%s','2004-01-01 02:34:56')) / 86400 *24 + cast(strftime("%H", time(strftime('%s','2012-01-01 12:00:00') - strftime('%s','2004-01-01 02:34:56'), 'unixepoch'))  as int) as text) 
        || ":" 
        ||  substr(time(strftime('%s','2012-01-01 12:00:00') - strftime('%s','2004-01-01 02:34:56'), 'unixepoch'), 4);
    70137:25:04
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say we want to make a function like minBy that returns all elements of
I have a flash conversion function that I call like this: var key:String=numToChar(keyboardEvent.charCode); currently
I want to make a function that takes an entered value and converts it
I want to make a function that is always running in xcode similar to
I want to make a function that automatically turns every Math function global example:
I want to make a function in standard ml that checks if a tree
I want to make a generic function in jquery for select all functionality. I
Let's imagine I want to make a templated function that returns the first element
I am in trouble with ocaml. I want to make a function that will
I want to make a function that being a decorator to another function will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.