Home » Developer & Programmer » Forms » Time Calculation (Forms 6i, Oracle 10g R2)
Time Calculation [message #527757] Thu, 20 October 2011 02:00 Go to next message
snsiddiqui
Messages: 172
Registered: December 2008
Senior Member
Dear All,

Currently I am working on payroll system where I have to calculate employees working hours/late coming hours/early going hours against its roster which is defined in the beginning of every month/week.

In roster form user define shift of every employee like

Code Name Shift
7 Saad Nafees A - 09:00 17:00
492 Muhammad Nasir Shahzad B - 17:00 01:00
243 Muhammad Tahir C - 01:00 09:00

Roster table structure
code varchar2
name varchar2
Shift date
Remarks varchar2

shift table structure
code varchar2
timein date
timeout date
latetime date
Hdaytime date

Oracle stores both date and time information in date data type, suppose today user change shift timings from 17:00 to 17:30 or user change timein/timeout in attendance form then oracle will store current date with user define timings.

Now this is the main problem which I am facing because whenever you calculate difference between timein and timeout or compare with its roster then output comes wrong because oracle returns total no of hours whenever you minus two dates.

I will be very grateful to all of you, if you will help me in this project.
Re: Time Calculation [message #527813 is a reply to message #527757] Thu, 20 October 2011 05:26 Go to previous messageGo to next message
Littlefoot
Messages: 21817
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Quote:
oracle returns total no of hours whenever you minus two dates

Wrong! Result is number of days.

OK, so what do you exactly need? Help in converting number of days into number of hours + minutes (such as 0.25 days = 6 hours 0 minutes) or what?
Re: Time Calculation [message #527954 is a reply to message #527813] Fri, 21 October 2011 00:53 Go to previous messageGo to next message
snsiddiqui
Messages: 172
Registered: December 2008
Senior Member
Yes, you right oracle returns no of days whenever you minus two dates.

Please check the image, we discuss about 10.10.2011 and the TIME IN is 08:47 its mean TIME IN is saved in database 10/10/2011 08:46 AM, if I changed TIME IN to 09:00 then TIME IN will be saved in database 10/01/2011 09:00 AM.

Now, if you want to check working hours of 10.10.2011 then you have to minus TIME IN - TIME OUT then you can not get correct working hours.

TIME IN - TIME OUT
10/01/2011 09:00:00 - 10/10/2011 17:30:00

  • Attachment: Pic1.jpg
    (Size: 126.01KB, Downloaded 815 times)
Re: Time Calculation [message #527965 is a reply to message #527954] Fri, 21 October 2011 01:40 Go to previous messageGo to next message
Littlefoot
Messages: 21817
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Your message is full of inconsistencies:
08:47      -> 08:46
10/10/2011 -> 10/01/2011

I can't follow what you are saying. Date format is awkward (what does "10/01" mean? Is it "Jan 10th" or "Oct 1st"?)

Anyway: if I had to calculate my working hours, I'd rather subtract TIME OUT - TIME IN. You did the opposite and got negative numbers.

Could you share the code you used to do the calculation? It is kind of difficult to debug code you can't see.
Re: Time Calculation [message #527970 is a reply to message #527965] Fri, 21 October 2011 01:59 Go to previous messageGo to next message
snsiddiqui
Messages: 172
Registered: December 2008
Senior Member
Yes, you are right I am subtracting TIME OUT - TIME IN therefore I am getting correct result, you can also check in image.

Yes, it is OCT 1st.

Actually, I want to know that if today I change TIME IN then oracle should save today's date with time but oracle is saving this month's starting date therefore I am unable to get correct result.
Re: Time Calculation [message #527973 is a reply to message #527970] Fri, 21 October 2011 02:11 Go to previous messageGo to next message
Littlefoot
Messages: 21817
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Quote:
if today I change TIME IN ...

That depends on what you EXACTLY do. By default, if you don't specify DATE component, it is truncated to the first of current month:
SQL> alter session set nls_date_format = 'dd.mm.yyyy hh24:mi';

Session altered.

SQL> select to_date('09:05', 'hh24:mi') from dual;

TO_DATE('09:05',
----------------
01.10.2011 09:05

SQL>
That seems to be your problem.

Image you attached contains 4 items: date_in, time_in, date_out, time_out. What do you have in a table? How many columns? 4 as well, or just two (date_in, date_out)? I guess that your life would be easier if it were only two columns. Otherwise, you'll have to check what's written in DATE_IN when saving TIME_IN and update the value accordingly to their combination.
Re: Time Calculation [message #527995 is a reply to message #527973] Fri, 21 October 2011 03:00 Go to previous messageGo to next message
snsiddiqui
Messages: 172
Registered: December 2008
Senior Member
Would you please tell me, how can I update the value of TIME IN with the combination of DATE IN and TIME IN?
Re: Time Calculation [message #528002 is a reply to message #527995] Fri, 21 October 2011 03:14 Go to previous messageGo to next message
Littlefoot
Messages: 21817
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
With TO_CHAR function, take DATE from DATE_IN and TIME from TIME_IN. Concatenate these values and transform them back to DATE datatype using TO_DATE function with the appropriate date format.
Re: Time Calculation [message #528027 is a reply to message #528002] Fri, 21 October 2011 05:20 Go to previous messageGo to next message
snsiddiqui
Messages: 172
Registered: December 2008
Senior Member
I applied your given suggestion but it is giving me error;

ORA-01861: literal does not match format string

:emp_attnd_mast.eam_atime := to_date(to_char(:emp_attnd_mast.eam_date,'DDMMYYYY')||to_char(:emp_attnd_mast.eam_atime,'HH24:MI'));
Re: Time Calculation [message #528036 is a reply to message #528027] Fri, 21 October 2011 05:33 Go to previous messageGo to next message
snsiddiqui
Messages: 172
Registered: December 2008
Senior Member
Sorry, I have done it.

Thanks for the co-operation.
Re: Time Calculation [message #528037 is a reply to message #528027] Fri, 21 October 2011 05:33 Go to previous messageGo to next message
Littlefoot
Messages: 21817
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
TO_DATE misses the appropriate date format mask, which should be - regarding what you wrote - 'DDMMYYYYHH24:MI'.
Re: Time Calculation [message #528054 is a reply to message #528037] Fri, 21 October 2011 06:04 Go to previous message
snsiddiqui
Messages: 172
Registered: December 2008
Senior Member
Once again I am really thankful to you for your good and helpful suggestions.
Previous Topic: tree_node
Next Topic: submenu issue in forms 6i
Goto Forum:
  


Current Time: Sun Aug 11 11:56:30 CDT 2024