开发者

How to add minutes to datetime?

I want to add minutes that already开发者_高级运维 exist in same table. I have a datetime and a duration. I want to get the start date/time as well as the end date/time.

I can use datetime but have to specify 'localtime' which doesn't work. I want the equivalent of DATEADD in SQL Server.


This is how you add 15 minutes to the current datetime.

SELECT datetime('now', '+15 Minute');


Try

datetime(strftime('%s', start_date) + minute_count * 60,  'unixepoch')

start_date – your start date;

minute_count – count of minutes as integer.


If you want to e.g. create a new entry in a database you can use the following statement

INSERT INTO tablename (created, expires) VALUES (
    datetime('now', 'localtime'),
    datetime('now', 'localtime', '+365 days')
);

datetime is here actually a shorthand for the strftime function. Creating time offsets is achieved with modifierts, there are many more modifiers possible. You can find it here in the documentation for Date And Time Functions

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜