Home » Developer & Programmer » Forms » parameter not pass with time (plsql)
parameter not pass with time [message #644528] Mon, 09 November 2015 03:46 Go to next message
mehboob110233
Messages: 55
Registered: February 2014
Location: Pakistan
Member

create or replace function get_total_time (p_out_time date, p_in_time date)
  return varchar2 is
  v_total_time varchar2(1000);
begin
  select lpad((trunc((p_out_time - p_in_time)) * 24), 2,0)||':'
           into v_total_time
    from dual;
  return v_total_time;
end;



Dear all i want to get hours from mentioned code.
but its not return me hour it return only '0' because data parameter not pass with time how can i pass with 'dd-mon-rrrr hh24:mi:ss' guid me please.
Re: parameter not pass with time [message #644530 is a reply to message #644528] Mon, 09 November 2015 04:34 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

SQL> create or replace function get_total_time (p_out_time date, p_in_time date)
  2    return varchar2 is
  3  begin
  4    return to_char((p_out_time-p_in_time)*24,'fm00')||':';
  5  end;
  6  /

Function created.

SQL> select get_total_time(sysdate+3/24,sysdate) hh from dual;
HH
-------------------------------------------------------------------
03:
Re: parameter not pass with time [message #644531 is a reply to message #644530] Mon, 09 November 2015 04:39 Go to previous messageGo to next message
mehboob110233
Messages: 55
Registered: February 2014
Location: Pakistan
Member

Not Sir , i want to get difference of time in

04:05:08
in this format
and want to convert this code in function i will pass two time and function return me above formatted time.
select lpad((trunc((p_out_time - p_in_time)) * 24), 2,0)||':'||
                  trunc(mod((sysdate - to_Date('09-nov-2015 09:11:04',
                                      'dd-mon-rrrr hh24:mi:ss')) * 24 * 60,
                   60)) || ':' ||
         trunc(mod((sysdate - to_Date('09-nov-2015 09:11:04',
                                      'dd-mon-rrrr hh24:mi:ss')) * 24 * 60 * 60,
                   60))
    from dual;
Re: parameter not pass with time [message #644532 is a reply to message #644528] Mon, 09 November 2015 04:39 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
What do you expect this function to return? What to you call "total time"? Your code looks suspicious; did you test what it really does, step-by-step?
SQL> with test as
  2    (select to_date('09.11.2015 11:33', 'dd.mm.yyyy hh24:mi') date_out,
  3            to_date('09.11.2015 10:23', 'dd.mm.yyyy hh24:mi') date_in
  4     from dual
  5    )
  6  select date_out - date_in result_1,
  7         trunc(date_out - date_in) result_2,
  8         trunc(date_out - date_in) * 24 result_3,
  9         lpad(trunc(date_out - date_in) * 24, 2, 0) result_4
 10  from test;

  RESULT_1   RESULT_2   RESULT_3 RE
---------- ---------- ---------- --
,048611111          0          0 00

SQL>


When subtracting two dates, you get number of days. So, if you meant to return number of hours (which multiplying with 24 suggests), why did you TRUNC the difference first?
Re: parameter not pass with time [message #644533 is a reply to message #644530] Mon, 09 November 2015 04:42 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
The main problem with your code is the fact that you're using trunc. The why you're using it it does the same job as floor - remove all decimals. That's not what you want.
Re: parameter not pass with time [message #644534 is a reply to message #644532] Mon, 09 November 2015 04:48 Go to previous messageGo to next message
mehboob110233
Messages: 55
Registered: February 2014
Location: Pakistan
Member

Dear sir,
Simply give me function which calculate time between two times let,s i want to calculate duty hour of the employee from there in_time and Out_time.
Re: parameter not pass with time [message #644535 is a reply to message #644534] Mon, 09 November 2015 04:51 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
mehboob110233 wrote on Mon, 09 November 2015 11:48

Simply give me function ...


Sure, if you give me your salary.
Re: parameter not pass with time [message #644536 is a reply to message #644531] Mon, 09 November 2015 04:52 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
Not Sir , i want to get difference of time in


I gave you the code for the part your function does not for what you didn't mention.
Now it should be easy to update my code to get what you want.
Give it a try.

Re: parameter not pass with time [message #644537 is a reply to message #644535] Mon, 09 November 2015 04:55 Go to previous messageGo to next message
mehboob110233
Messages: 55
Registered: February 2014
Location: Pakistan
Member

funny sir,
Re: parameter not pass with time [message #644538 is a reply to message #644537] Mon, 09 November 2015 05:00 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Actually, it is sad. You expect someone else do "give you a function". Well, this is a public forum, someone of the members might do it. But that's not the right way - forum members should HELP you write the function, not write it for you. You got several suggestions, it is time for you to apply them to your own code.
Re: parameter not pass with time [message #644539 is a reply to message #644538] Mon, 09 November 2015 05:29 Go to previous messageGo to next message
mehboob110233
Messages: 55
Registered: February 2014
Location: Pakistan
Member

Thanks Very much sir,
i solved it.
basically when i pass parameter to function then it truncate time from the parameter now i send parameter to function with varhcar2 then convert it in to_date format now work properly



Thanks sir again
Re: parameter not pass with time [message #644542 is a reply to message #644539] Mon, 09 November 2015 06:03 Go to previous message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Please post the final code.

Previous Topic: Forms Personalization
Next Topic: forms not running
Goto Forum:
  


Current Time: Thu Apr 18 16:16:21 CDT 2024