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.  So, I 
thought that if I concatenate the result to the with to '+XXX hours' it would 
work.  But, you all probably know the result.  So, here is what I have tried 
last:

select CASE
  WHEN time('now','localtime','+5.5 hours') > '17:00:00' THEN
    datetime('now','localtime','+1 day','start of day','+8.5 hours','+' || 
time('now','localtime','+5.5 hours') - '17:00:00' || ' hours')
  ELSE
    datetime('now','localtime','+5.5 hours')
  END;

but I get nothing for result:

sqlite> select CASE
   ...>   WHEN time('now','localtime','+5.5 hours') > '17:00:00' THEN
   ...>     datetime('now','start of day','+1 day','+8.5 hours','+' || time('now
','+5.5 hours','localtime') - '17:00:00' || ' hours')
   ...>   else
   ...>     datetime('now','localtime','+5.5 hours')
   ...>   END;


sqlite>

Any help would be greatly appreciated.  Thanks.

Reply via email to