MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 1st, 2013, 01:07 AM
darroite darroite is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 3 darroite User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 22 sec
Reputation Power: 0
Timestamp calculation

I have three columns on my table, "in", "out" and "totaltime" all of them are timestamp type. So I need to calculate the time a specific person have been logged in the system, and show this result at totaltime column...

this is my code:
String sql = "update school2 set totaltime = TIMESTAMPDIFF(in, out) where id = '"+Integer.parseInt(text_id.getText())+"' ";

it does not work...
I will appreciate any suggestion.

Reply With Quote
  #2  
Old February 1st, 2013, 01:41 AM
r937's Avatar
r937 r937 is online now
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,377 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 7 h 40 m 36 sec
Reputation Power: 4140
Quote:
Originally Posted by darroite
I have three columns on my table, "in", "out" and "totaltime" all of them are timestamp type.
actually, you also have another column in the table, called "id"

you should never store a value in a column like totaltime because it can easily be calculated, so you should remove the totaltime column from your table

in other words, your entire UPDATE statement is not necessary

instead, do the calculation in the SELECT statement when you retireve data for a person

as to why your calculation "doesn't work" i'm afraid i'm not familiar with the "doesn't work" error message

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
  #3  
Old February 1st, 2013, 02:15 AM
darroite darroite is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 3 darroite User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 22 sec
Reputation Power: 0
First of all thank you for replay,
I agree with you on the part when you say I should do all my calculation on my select statement, by I will need to keep one record of the total time each person has stood logged on the system, that is why I have created the "totaltime" column.

Reply With Quote
  #4  
Old February 1st, 2013, 03:01 AM
r937's Avatar
r937 r937 is online now
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,377 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 7 h 40 m 36 sec
Reputation Power: 4140
Quote:
Originally Posted by darroite
...that is why I have created the "totaltime" column.
that's not a good reason, but if you want it that way, go right ahead

Reply With Quote
  #5  
Old February 1st, 2013, 01:07 PM
darroite darroite is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 3 darroite User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 22 sec
Reputation Power: 0
I am actually trying to insert the result of the sum of logged time into a new table.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Timestamp calculation

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap