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.
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:
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:Example: