Getting the amount of time from one epoch to another

I currently have an epoch number stored in a database.

How would I get the amount of days/hours/minutes from now until that time?

I.E I have the epoch time: 1477340561

How would I get the amount of days from now until that epoch time?

Thank you.

local secondsPassedSince = currentTimeStamp - 1477340561
local days = Math.floor( secondsPassedSince / 60 / 24 / 60 );
local hour = parseInt( secondsPassedSince / 3600 ) % 24;
local mins = parseInt( secondsPassedSince / 60 ) % 60;
local secs = Math.floor( secondsPassedSince % 60 );

Thank you! That worked.

I have another question though.

What would be the best way of checking to see if a value changed on a client quickly?

Would it be better to use a timer.Create every second or two, or some other method like a hook?


What’re you trying to accomplish?

Well, a few things.

The major one is checking to see if a bool in a database has changed(using mysqloo,and a query), and if it has, then to do something in-game(basically like a listen server)

Assuming it’s a database shared with a php script, for donation perks or something, unless you want to start messing about with sockets you’re probably fine with a timer on some reasonable interval, depending on how urgent the data is.

I do use sockets for other things.

And yes, it is a donation script that uses paypals IPN to give perks.

I wanted to setup a timer to check the database for changes with a player after about 30~ seconds.

This will most likely be my final question, but is there an easier way to check for updates in a database, besides having to do a query with mysqloo like: SELECT * FROM database WHERE x=y?

Not really. None of the SQL modules for Gmod can interact with outside programs.