Home » Developer & Programmer » Forms » to calculate total hours
to calculate total hours [message #137819] Sat, 17 September 2005 02:03 Go to next message
gauravpuri
Messages: 26
Registered: August 2005
Location: Chennai
Junior Member

hi

i have 2 field in my form in which i am entering start and end time respectively.these two fields are of date type having format hh24:mm:ss.
Now i want to calculate total hours based on start and end time
and my total hours field is number.
Please help me
Re: to calculate total hours [message #137843 is a reply to message #137819] Sat, 17 September 2005 10:13 Go to previous messageGo to next message
saadatahmad
Messages: 452
Registered: March 2005
Location: Germany/Paderborn
Senior Member

hi,
first change your time format from hh24:mm:ss to hh:mi:ss (it's mi not mm. mm is for month number not minutes)
Secondly, you can calculate the hours this way.
saadat@anba> SELECT * FROM test2;

TIME1     TIME2
--------- ---------
27-SEP-05 17-SEP-05
01-SEP-05 01-SEP-05

Elapsed: 00:00:00.00
saadat@anba> SELECT TO_CHAR(time1, 'DD-MON-YYYY HH:MI:SS') date1, TO_CHAR(time2, 'DD-MON-YYYY HH:MI:SS') time2,
  2                 (time1 - time2) * 24 time_difference
  3  FROM test2
  4  /

DATE1                TIME2                TIME_DIFFERENCE
-------------------- -------------------- ---------------
27-SEP-2005 12:00:00 17-SEP-2005 12:00:00             240
01-SEP-2005 12:33:00 01-SEP-2005 10:33:00               2

Elapsed: 00:00:00.00

You can have a When-Validate-Item trigger on your time2 field and populate the time difference on another field.

Regards.
Re: to calculate total hours [message #137946 is a reply to message #137843] Mon, 19 September 2005 00:48 Go to previous messageGo to next message
gauravpuri
Messages: 26
Registered: August 2005
Location: Chennai
Junior Member

hi saadatahmad,

thanks for urs response.
yours query is ok if i put time say 9:00,19:00 gives 10 hrs .
but can i put 9:00 am ,6:00 pm to give 9 hrs.


Re: to calculate total hours [message #137962 is a reply to message #137843] Mon, 19 September 2005 02:49 Go to previous messageGo to next message
saadatahmad
Messages: 452
Registered: March 2005
Location: Germany/Paderborn
Senior Member

yes
I entered these times in forms and the format mask was hh:mi:ss am
saadat@anba> desc test2
 Name                                                                    Null?    Type
 ----------------------------------------------------------------------- -------- ----------------------------------------
 TIME1                                                                            DATE
 TIME2                                                                            DATE

saadat@anba> SELECT * FROM test2;

TIME1     TIME2
--------- ---------
01-SEP-05 01-SEP-05
01-SEP-05 01-SEP-05
01-SEP-05 01-DEC-05
01-SEP-05 01-SEP-05

Elapsed: 00:00:00.00
saadat@anba> SELECT TO_CHAR(time2, 'DD-MON-YYYY HH:MI:SS AM') time2, TO_CHAR(time1, 'DD-MON-YYYY HH:MI:SS AM') time1,
  2  (time2 - time1) * 24 time_difference
  3  FROM test2
  4  /

TIME2                   TIME1                   TIME_DIFFERENCE
----------------------- ----------------------- ---------------
01-SEP-2005 03:33:59 PM 01-SEP-2005 03:33:59 PM               0
01-SEP-2005 09:33:36 PM 01-SEP-2005 10:22:30 AM          11.185
01-DEC-2005 04:09:22 PM 01-SEP-2005 08:12:30 AM      2191.94778
01-SEP-2005 08:00:00 PM 01-SEP-2005 08:00:00 AM              12

Elapsed: 00:00:00.00


Regards.
Re: to calculate total hours [message #137988 is a reply to message #137962] Mon, 19 September 2005 05:32 Go to previous message
gauravpuri
Messages: 26
Registered: August 2005
Location: Chennai
Junior Member

hi saadatahmad,

yes its working fine . thanks for urs help


Previous Topic: error : frm 40010 : cannot read from d:\brn (merged)
Next Topic: Run the form
Goto Forum:
  


Current Time: Fri Sep 20 05:39:43 CDT 2024