in reply to Totaling Time

No offense, but this seems way to vague. We can't tell what the table scheme is, what data you may or may not already have in your script etc. Even if that wasn't a problem, I can't tell if you want the SQL statement that does something or you need a perl snippet

Please write exactly what you need. And details, please.... details...

Replies are listed 'Best First'.
Re: Re: Totaling Time
by nlafferty (Scribe) on Jul 25, 2001 at 22:27 UTC
    In the TIME TOTAL CALCULATION SUBROUTINE i need to take the SQL fields (start_hour, start_minute, end_hour, end_minute) from a row consistion of (oid,emp_id,date,f_name,l_name,start_hour, start_minute,start_stamp, end_hour, end_minute, end_stamp, comment). Then update the 'total_time' field WHERE oid = $sav_oid Field with that total. Oh yes. 24 hour format would be good.
    #!/usr/bin/perl ### clock_out.cgi use CGI qw/:standard/; require "common.sub"; $oid = $ENV{QUERY_STRING}; $sav_oid = $oid; $end_hour = &filter(param(hour)); $end_minute = &filter(param(minute)); $comment = &filter(param(comment)); print header; &Create_DB_Connection; &clock_out; &print_output; # Disconnect from the database $sth->finish; $dbh->disconnect; ################ BEGIN CLOCKOUT SUBROUTINE sub clock_out{ $SQL = "UPDATE timeclock SET end_hour = '$hour', end_minute = '$minute', end_stamp = CURRENT_TIMESTAMP, WHERE oid = '$sav_oid' "; &Do_SQL; } # End of clock_out ################ END CLOCKOUT SUBROUTINE ################ BEGIN TIME TOTAL CALCULATION SUBROUTINE sub calc_total{ $SQL = "select oid,* FROM timeclock WHERE oid = $sav_oid"; &Do_SQL; ################ END WRITE DATA SUBROUTINE ################ BEGIN PRINT OUTPUT SUBROUTINE sub print_output{ print<<HTML; <BODY BGCOLOR="#F1EDD3"> <CENTER><FONT SIZE=5 FACE=ARIAL> Record added to database <P> <CENTER> </CENTER> </P> </FONT></CENTER> </BODY></HTML> HTML } # End of subroutine ################ END PRINT OUTPUT SUBROUTINE

      So if I read this correctly, you want to figure out the time that elapsed between start_hour, start_min, end_hour, and end_min, and then store it back in your db

      I think I can safely say that it's impossible to detemine ( correctly ) the amount of time that has elapsed by just knowing the hour and minutes, as RheTbull says.

      You would need to have some sort of date/time entries for start time and end time, then I think Postgres provides you with ways to calculate an interval type.