On 7/29/15, jose isaias cabrera <jicman at cinops.xerox.com> wrote: > > Greetings! > > I am trying to calculate a date using sqlite date and time functions. > Perhaps, one of you GURUs can help this poor soul. I have been trying to > figure it out, but I know I am lack the understanding. I read the > documentation for it, > > https://www.sqlite.org/lang_datefunc.html > > but I can not seem to find the way to do this. The idea is this one, there > will be an input of hours, which in this case will be 5.5 hours, that will > be added to the actual time. For example, if it's 10AM, adding 5.5 hours > will give 3:30 PM. This is easy, > > datetime('now','localtime','+5.5 hours') > > the problem happens if it is after 5PM. For example, say it is 2PM, adding > 5.5 hours to it will give 7:30PM. What I am trying to do is to add the > amount of hours over 5PM, which is, > > time('now','localtime','+5.5 hours') - '17:00:00' > > to 8.5 hours to the start of the next day and select that date and time.
SELECT CASE WHEN time('now','+5.5 hours','localtime') > '17:00:00' THEN datetime('now','+21.0 hours','localtime') ELSE datetime('now','+5.5 hours','localtime') END; -- D. Richard Hipp drh at sqlite.org