Skip to content
Advertisement

How to add a minutes column to date column sql

I may sound silly asking it – but I have the need to add a value derived from one column of database to the other which is the date.

Following is the image of data I have – timeelapsed/60000 gives me the duration of task in minutes and I would require the same to be deducted from the lastupdatedtime to know the time when was the task picked. Please help!

enter image description here

I have attempted as per your suggestion

lastupdatedtime – (timeelapsed/60000) * interval ‘1 minute’ as task_pick_datetime,

But I see the difference appearing is huge.

For instance, the audited time is 2020-03-12 17:41:39.224, duration in min is 3.06 but the task pick time shows 2020-03-12 12:08:35.417 which is 5 hours difference. Unsure where am I going wrong.

enter image description here

Advertisement

Answer

In Standard SQL (which is the tag on your question), you can use:

select lastupdatetime - (timeelapsed/60000) * interval '1 minute' as task_pick_datetime

However, date/time functions are notoriously database dependent, so your database may not support this syntax.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement