in reply to Re: Totaling Time
in thread Totaling Time

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

Replies are listed 'Best First'.
Re: Re: Re: Totaling Time
by lestrrat (Deacon) on Jul 25, 2001 at 22:37 UTC

    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.