Reputation: 3
Right basically I got a timer and I was wondering if there is a way to create a seperate timer to make it update every 5 minutes. Im not sure how to use new databases.
Upvotes: 0
Views: 296
Reputation: 22
InJailTime
, in addition to the field timeleft
Then you will create a SQL job which runs every a minute to update the "TimeLeft" field with the remaining time as shown in this script
UPDATE [TableName] SET TimeLeft = DATEDIFF(MINUTE, InJailTime ,GETDATE())
Upvotes: 0
Reputation: 6060
You would be better off creating a field called when_I_get_out
datetime, and set it to DATEADD(Minute, 5, GETDATE())
. This will set the time in that field to 5 minutes in the future. If you want a timeleft
, add a computed column timeleft
using DATEDIFF. Here's an example:
CREATE TABLE [FOO] (
[when_I_get_out] datetime,
[timeleft] AS CASE WHEN GETDATE() > [when_I_get_out] THEN 0 ELSE DATEDIFF(Minute, GETDATE(), when_I_get_out) END
)
INSERT INTO [FOO] ([when_I_get_out]) VALUES (DATEADD(Minute, 5, GETDATE()));
Using this, timeleft
will be the number of minutes remaining, but 0 if the time is up.
Upvotes: 2