question

Msvelu avatar image
Msvelu asked

I want to minus the time stored in database to current time

My database time is like LogDateTime 2015-05-28 10:57:01.000 Minus the database value time with the current time.. Anyone help with the code....
time
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Kev Riley avatar image
Kev Riley answered
Do you mean you want to know the difference between this stored time and the current time? select datediff(minute, LogDateTime, getdate()) of course you can change the `minute` parameter to what you need : seconds, hours, days, months..... https://msdn.microsoft.com/en-us/library/ms189794.aspx
3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Msvelu avatar image Msvelu commented ·
Hi Kev its good to see you again.. I already tried this but the result coming wrongly is post my sql query below SELECT + CAST(DATEDIFF(second, LogDateTime, GETDATE()) / 60 / 60 / 24 / 7 AS VARCHAR(20)) + ' weeks, ' + CAST(DATEDIFF(second, LogDateTime, GETDATE()) / 60 / 60 / 24 % 7 AS VARCHAR(20)) + ' days, ' + CAST(DATEDIFF(second, LogDateTime, GETDATE()) / 60 / 60 % 24 AS VARCHAR(20)) + ' hours, ' + CAST(DATEDIFF(second, LogDateTime, GETDATE()) / 60 % 60 AS VARCHAR(20)) + ' minutes and ' + CAST(DATEDIFF(second, LogDateTime, GETDATE()) % 60 AS VARCHAR(20)) + ' seconds' from tb_VTSData;
0 Likes 0 ·
Kev Riley avatar image Kev Riley ♦♦ commented ·
What's wrong? Have you any example data?
0 Likes 0 ·
Msvelu avatar image Msvelu commented ·
MY SYSTEM GETTING "SYSTEM TIME" wrongly
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.