Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

time calculation problem 1

Status
Not open for further replies.

kaptlid

Technical User
Nov 26, 2006
86
US
I am using mysql version 4.1.13 and I keep getting a 1064 syntax error on this query.

select * , timediff(in , out) as timespent from `timesheet`

the table structure is

date, in, out,
date is a standard date column, in and out are time columns,

I am just trying to get the difference between the hours and minutes.

Thanks,
 
in" and "out" are keywords. You need to enclose them in "backticks": `in`, `out`. "date" is also a keyword. If you can change those field names, it would be even better.
 
thanks that worked, I did not realize that.
 
ok I have another question. I tried getting rid of the seconds in the time which succeeded, but the difference results come out improper on the minutes.

I tested a time of 2:45 - 2:30am and the result comes out to 12:15 instead of 00:15. Why is that?

SELECT DATE_FORMAT(`date`, '%c/%e/%Y') as `date` ,TIME_FORMAT(`in`,'%l:%i%p') as `in`, TIME_FORMAT(`out`,'%l:%i%p') as `out`,TIME_FORMAT( timediff(`out`,`in`),'%l:%i') AS `time spent`,from timesheet
 
I figured out what I need to do a different way:

SELECT DATE_FORMAT(`date`, '%c/%e/%Y') as `date` ,TIME_FORMAT(`in`,'%l:%i%p') as `in`, TIME_FORMAT(`out`,'%l:%i%p') as `out`,left(timediff(`out`,`in`),5) AS `time spent' from timesheet
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top