Jump to content

Storing time active in MySQL

Go to solution Solved by Mr_KoKa,

I would use integer for time in seconds.

Hey there!

 

I've worked with MSSQL for a couple of years now but I never worked with anything like this :Þ
I moved over to MySQL because the system I'm working with only supports MySQL.

 

My question is, how do I store a 'total activity' value? For instance: "32 days, 12 hours, 15 minutes and 9 seconds" total. How do I store this so I can add like 5 minutes to it later on?
 

Maybe a Integer, or a DateTime kind of object?
Can anybody help me out, any tips are helpfull!

Link to comment
Share on other sites

Link to post
Share on other sites

You can use DateTime and then UPDATE using DATE_ADD mysql function which would look like

UPDATE table SET date = DATE_ADD(date, INTERVAL 5 MINUTE) WHERE id = 1

Unless you won't be doing that using queries but you will select data, and then alter it in your code, then update with new value, if it is the case you would need to specify language.

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Mr_KoKa said:

You can use DateTime and then UPDATE using DATE_ADD mysql function which would look like


UPDATE table SET date = DATE_ADD(date, INTERVAL 5 MINUTE) WHERE id = 1

Unless you won't be doing that using queries but you will select data, and then alter it in your code, then update with new value, if it is the case you would need to specify language.

But I wan't it to be like 0000-01-02 12:15:09.

So its only his active time.

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Mr_KoKa said:

I would use integer for time in seconds.

I was thinking about the same thing, but thought there maybe was a better solution.
Thanks for the help

Link to comment
Share on other sites

Link to post
Share on other sites

Another option is to store the length of each activity separately (still using integer as Mr_KoKa suggested) instead of just storing the sum. You can still store the sum if you want or you can get it when needed with SELECT SUM(...).

 

Whether this is of any benefit for you depends on what you want to do with the information.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×