Add Time value to a Date value

Hi
COLUMN A is a DATE TYPE i.e. *14-MAR-13 12:30*
COLUMN B is a CHAR Type for hours and minutes: i.e. *01:45*.
I'm trying to sum (in SQL) the time in Col A with Col B, the result should be: 14:15
I'm not too sure how to proceed
THanks
Ruben

Ruben_920841 wrote:
Hi Frank,
Thank you for your quick reply.
However, I'm not sure I understand why you insert "TRUNC (b_date)" in your code below. Can you please explain?
>
WITH     got_b_date     AS
     SELECT     a, b
     ,     TO_DATE (b, 'HH24:MI')     AS b_date
     FROM     table_x
SELECT     a, b
,     a + ( b_date
     - TRUNC (b_date)
     )      AS a_plus_b
FROM table_x
>TO_DATE (b, 'HH24:MI') converts a string (such as '01:45') into a DATE (such as 1:45 AM on April 1, 2013). Since we're not passing a day of the month, month or year, those all take default values.
If d is a DATE, then TRUNC (d) is the earliest DATE (miodnight) on the same calendar day.
If d1 and d2 are DATEs, then d1 - d2 is the number of days (not necessarily an integer) that d1 is after d2.
If d is a DATE and n is a NUMBER (not necessarily an integer), then d + n is a DATE n days after d.
Put this all together and what do we have, given that b is '01:45'
b_date is 1:45 AM on some default day (for this solution, it doesn't matter which day)
TRUNC (b_date) is midnight on that same calendar day.
b_date - TRUNC (b_date) is a NUMBER, the number of days that 1:45 is after midnight (1:45 is 1.75 hours, and a day is 24 hours, so that comes to 1.75 / 24 = .072916666... days.)
a + (b_date - TRUNC (b_date)) is a DATE, .072916666... days (that is, 1.75 hours) after a.
Notice that Solomon did almost the same thing, only Solomon used the fact that the default day of the month in TO_DATE is 1, and that the default month and year are the same month and year that SYSDATE returns, so b_date - TRUNC (b_date) is the same as b_date - TRUNC (SYSDATE, 'MONTH').

Similar Messages

  • How to add Time field in the Date Calender in OAF screen

    Hi All,
    is there a way to add time field in the date calender, so that the user can set the time and select the date, then return the date/time to the specified field?
    or is there any slandered calender that has this functionality?
    Regards,
    Mahdi Charara

    Hi Mahdi ,
    If you are working on standard page then you can create a new item by personalization and set the DataType as : DATETIME it will display
    date as well as time .
    For custom page - you can create a new item as desired in anywhere in page and set the DataType as : DATETIME it will show both time
    and date .
    Is this what you looking for ?
    --Keerthi                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Column with header data value

    Hi All.
    I have a control file which i need to add a column with header data value.
    example
    data file:
    123456;201303
    santiago;producto1;100
    santiago;producto2;200
    valparais;producto1;400
    valparais;producto3;900
    The control file skip the first column and load the three columns on the table, but, now i need to add other column with 201303 value constant of the first record and load it on the table.
    Then
    select * from table:
    santiago producto1 100 201303
    santiago producto2 200 201303
    valparais producto1 400 201303
    valparais producto3 900 201303
    How i do this in the control file?
    Regards!

    SCOTT@orcl_11gR2> host type test.dat
    123456;201303
    santiago;producto1;100
    santiago;producto2;200
    valparais;producto1;400
    valparais;producto3;900
    SCOTT@orcl_11gR2> host type test1.ctl
    options (load=1)
    load data
    infile test.dat
    replace
    into table onecol_onerow
    fields terminated by ';'
    trailing nullcols
    (filler1 filler, newcol)
    SCOTT@orcl_11gR2> host type test2.ctl
    options (skip=1)
    load data
    infile test.dat
    append
    into table test_tab
    fields terminated by ';'
    trailing nullcols
    (col1, col2, col3,
    newcol expression "(select newcol from onecol_onerow)")
    SCOTT@orcl_11gR2> create table onecol_onerow
      2    (newcol number)
      3  /
    Table created.
    SCOTT@orcl_11gR2> create table test_tab
      2    (col1   varchar2(15),
      3     col2   varchar2(15),
      4     col3   number,
      5     newcol number)
      6  /
    Table created.
    SCOTT@orcl_11gR2> host sqlldr scott/tiger control=test1.ctl log=test1.log
    SQL*Loader: Release 11.2.0.1.0 - Production on Mon May 6 10:46:44 2013
    Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
    Commit point reached - logical record count 1
    SCOTT@orcl_11gR2> select * from onecol_onerow
      2  /
        NEWCOL
        201303
    1 row selected.
    SCOTT@orcl_11gR2> host sqlldr scott/tiger control=test2.ctl log=test2.log
    SQL*Loader: Release 11.2.0.1.0 - Production on Mon May 6 10:46:45 2013
    Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
    Commit point reached - logical record count 4
    SCOTT@orcl_11gR2> select * from test_tab
      2  /
    COL1            COL2                  COL3     NEWCOL
    santiago        producto1              100     201303
    santiago        producto2              200     201303
    valparais       producto1              400     201303
    valparais       producto3              900     201303
    4 rows selected.

  • Date Picker Doesn't Like Retrieved or Typed In Date Values

    I have more than one Region on a page, so I retrieve the column values for a region this way:
    (On LOad, Before Header, Once per Page Visit)
    BEGIN
    EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_DATE_FORMAT='''||:pick_date_format_mask||'''';
    FOR request_rec IN (SELECT dev_requested_ind,
    dev_requested_dttm,
    dev_analyst_seq,
    dev_completed_ind,
    dev_completed_dttm,
    dev_dba_seq,
    sit_requested_ind,
    sit_requested_dttm,
    sit_analyst_seq,
    sit_completed_ind,
    sit_completed_dttm,
    sit_dba_seq,
    uat_requested_ind,
    uat_requested_dttm,
    uat_analyst_seq,
    uat_completed_ind,
    uat_completed_dttm,
    uat_dba_seq,
    prd_requested_ind,
    prd_requested_dttm,
    prd_analyst_seq,
    prd_completed_ind,
    prd_completed_dttm
    FROM request_tbl
    WHERE request_seq = :p16_request_seq)
    LOOP
    :p16_dev_requested_ind := request_rec.dev_requested_ind;
    :p16_dev_requested_dttm := request_rec.dev_requested_dttm;
    :p16_dev_analyst_seq := request_rec.dev_analyst_seq;
    :p16_dev_completed_ind := request_rec.dev_completed_ind;
    :p16_dev_completed_dttm := request_rec.dev_completed_dttm;
    :p16_dev_dba_seq := request_rec.dev_dba_seq;
    :p16_sit_requested_ind := request_rec.sit_requested_ind;
    :p16_sit_requested_dttm := request_rec.sit_requested_dttm;
    :p16_sit_analyst_seq := request_rec.sit_analyst_seq;
    :p16_sit_completed_ind := request_rec.sit_completed_ind;
    :p16_sit_completed_dttm := request_rec.sit_completed_dttm;
    :p16_sit_dba_seq := request_rec.sit_dba_seq;
    :p16_uat_requested_ind := request_rec.uat_requested_ind;
    :p16_uat_requested_dttm := request_rec.uat_requested_dttm;
    :p16_uat_analyst_seq := request_rec.uat_analyst_seq;
    :p16_uat_completed_ind := request_rec.uat_completed_ind;
    :p16_uat_completed_dttm := request_rec.uat_completed_dttm;
    :p16_uat_dba_seq := request_rec.uat_dba_seq;
    :p16_prd_requested_ind := request_rec.prd_requested_ind;
    :p16_prd_requested_dttm := request_rec.prd_requested_dttm;
    :p16_prd_analyst_seq := request_rec.prd_analyst_seq;
    :p16_prd_completed_ind := request_rec.prd_completed_ind;
    :p16_prd_completed_dttm := request_rec.prd_completed_dttm;
    END LOOP;
    END;
    p16_dev_requested_dttm is defined as a Date Picker (use application format mask)
    The data source is a Date column called dev_requested_dttm. I haven't defined a format mask for it. (I have tried using &PICK_DATE_FORMAT_MASK..)
    The Application Format Mask is defined as a Subsitution String called
    PICK_DATE_FORMAT_MASK
    with a value of
    MM/DD/YYYY HH:MI AM
    The retrieved column value for p16_dev_requested_dttm looks fine, but when I click the date picker pushbutton, I get this message:
    Not Found
    The requested URL /pls/htmldb/wwv_flow_utilities.show_as_popup_calendar was not found on this server.
    Oracle-Application-Server-10g/10.1.2.0.0 Oracle-HTTP-Server Server at edwdev.dhhs.state.nh.us Port 7779
    I also get a line in my log file,
    /vg02lvol1/app/oracle/product/htmldb/Apache/Apache/logs/error_log.1133956800:
    [Wed Dec  7 16:23:43 2005] [error] [client 172.16.252.76] [ecid: 1133990623:172.17.96.35:1802:0:9870,0] mod_plsql: /pls/htmldb/wwv_flow_util
    ities.show_as_popup_calendar HTTP-404 ORA-01849: hour must be between 1 and 12\nORA-06512: at "FLOWS_020000.WWV_FLOW_UTILITIES", line 1801\n
    ORA-06512: at line 22\n
    This happens with both FireFox and Internet Explorer.
    Any ideas what's causing this?
    -F
    Message was edited by:
    Fred C Willingham

    Fred,
    Unfortunately, the answer is no to both of your questions.
    There is no way for you as a developer to control which date is highlighted in the popup calendar. It will always highlight the current day (if you're displaying a month that contains the current day). This is an interesting and prudent suggestion, and one which we'll consider for an upcoming release of HTML DB.
    With regards to your second point, that also is something we should consider for an upcoming release of HTML DB. This isn't impossible for us to do, it was just designed to work in the current fashion. If you look at the generated HTML for the Date Picker item on the page (not the popup calendar itself, but the page on which the item is rendered), we break out each element of the date value into discrete components. When we instead rely upon the user entered value, garbage or date values not conforming to the date format mask are easily entered. And the question is - what to do then? Raise an error immediately, still popup the calendar and show the current month, etc. So we've tried to be fairly strict about the date values and format masks for the popup calendar, hence the implementation you see.
    Thanks again for your comments.
    Joel

  • Issue with using formatted date value column in order by clause...

    Hi,
    1) Through a function I am listing all the months in a year.
    like JAN-2007, FEB-2007,MAR-2007......
    2) i am comparing these values against a date value column in a table.
    And if there are no values in a particular period it will return a null value (simply to say, i am using an outer join)
    3) The issue.....
    When join both the queries then the order of the dates is not mainted .....
    My requirement is......
    Jan-2007 = 3
    Feb-2007 = 5
    Mar-2007 = null
    etc.....
    should be acheived.
    But I end up in the alphabetical order of the months....
    like
    Apr-2007 = 5
    Aug-2007 = 10
    etc.....
    Can anybody let me know how can i acheive my resultant output to be ordered by the date and not by character.
    When I use the date column in the order by I run into an error....
    saying....
    ORA-01858: a non-numeric character was found where a numeric was expected
    Its a kind of urgent...
    Any help is appreciated....
    KK

    When I use a outer join as follows....
    "and upper(to_char(a.task_planned_start_date,'mon-rrrr')) = d.period_name(+)"
    All the null periods are ending at the bottom.It's standard behavoiur.
    Seems, you need to sort by a.task_planned_start_date.
    Look below:
    SQL> select e.ename, ec.ename from emp e, emp_copy ec
      2  where e.empno = ec.empno(+);
    ENAME      ENAME
    SMITH      SMITH
    ALLEN
    WARD       WARD
    JONES
    MARTIN     MARTIN
    BLAKE
    CLARK      CLARK
    SCOTT
    KING       KING
    TURNER
    ADAMS      ADAMS
    JAMES
    FORD       FORD
    MILLER
    14 rows selected.
    SQL> select e.ename, ec.ename from emp e, emp_copy ec
      2  where e.empno = ec.empno(+)
      3  order by ec.ename
      4  /
    ENAME      ENAME
    ADAMS      ADAMS
    CLARK      CLARK
    FORD       FORD
    KING       KING
    MARTIN     MARTIN
    SMITH      SMITH
    WARD       WARD
    JAMES
    TURNER
    ALLEN
    MILLER
    BLAKE
    JONES
    SCOTT
    14 rows selected.
    SQL> select e.ename, ec.ename from emp e, emp_copy ec
      2  where e.empno = ec.empno(+)
      3  order by e.ename
      4  /
    ENAME      ENAME
    ADAMS      ADAMS
    ALLEN
    BLAKE
    CLARK      CLARK
    FORD       FORD
    JAMES
    JONES
    KING       KING
    MARTIN     MARTIN
    MILLER
    SCOTT
    SMITH      SMITH
    TURNER
    WARD       WARD
    14 rows selected.Rgds.

  • Converting seconds value to a date

    Hi,
    I have date column as integer like 1212638737.Could anyone tell me the way of converting this value to corresponding date value?

    user11365275 wrote:
    I have date column as integer like 1212638737.Could anyone tell me the way of converting this value to corresponding date value?How is the number to be converted to a date? Its not a Julain date because the number is way too big

  • Exclude weekends when substracting between two date values

    Hi All,
    I created a variable to get the value between 2 date values.
    v_lag_days := TRUNC (l_header_rec.request_date) - TRUNC (SYSDATE);
    if l_header_rec.request_date = sysdate i.e. 17-Feb-12 then it is fine, I will get the value as '0' which is correct.
    But if l_header_rec.request_date = '20-Feb-12' (for example), it will give me as '3', but I should get the value as '1' excluding weekends.
    When ever with in the 2 date values if it contains weekends, it should exclude those weekend days and should give me the value in the variable.
    If you are not able to get my point clearly, please let me know.
    Could anyone please let me know the logic for my scenario. Please help me out that would be really appreciated.
    Thanks in advance,
    Satya.

    Hi Satya.
    This is the same example, without including the final day.
    WITH aux1 AS
         SELECT
              CASE WHEN TO_NUMBER(TO_CHAR(TO_DATE(:date1,'YYYYMMDD')+(LEVEL-1),'D')) >= 6
                   THEN 0
                   ELSE 1
              END inc
         FROM dual
         CONNECT BY LEVEL <= (TO_DATE(:date2,'YYYYMMDD') - TO_DATE(:date1,'YYYYMMDD'))
    SELECT SIGN(:date2 - :date1)*SUM(inc) num_of_days FROM aux1;
    -- ':date2 = 20120217'
    -- ':date1 = 20120210'
    NUM_OF_DAYS
              5
    -- ':date2 = 20120220'
    -- ':date1 = 20120217'
    NUM_OF_DAYS
              1
    -- ':date2 = 20120217'
    -- ':date1 = 20120217'
    NUM_OF_DAYS
              0Hope this helps.
    Best Regards
    Edited by: sKr on 17-feb-2012 9:04 Improved for date2 = date1

  • How to campare two date values ?

    Hi,
    I want to compare two string values which has date values.
    Here i post my sample code :
    import java.util.*;
    public class Now {
    public static void  main(String arg[]) {
    try{
        String pre_date="";
        Calendar cal = Calendar.getInstance(TimeZone.getDefault());
         String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
        java.text.SimpleDateFormat sdf =
        new java.text.SimpleDateFormat(DATE_FORMAT);
        sdf.setTimeZone(TimeZone.getDefault());
         String sdd= sdf.format(cal.getTime());
         String sysdat = sdd.substring(0,10);
         String pdate = "2007-02-08 18:11:44.0";
         pre_date = pdate.substring(0,10);
         System.out.println("sysdate is   "+sysdat);
         System.out.println("previous date is   "+pre_date);
         if ((pre_date==sysdat)) {
              System.out.println("hai ");
         else{
              System.out.println("welcome ");
        catch(Exception e){
              System.out.println("Error in file "+e.getMessage());
              e.printStackTrace();
    }Here the else part has been executed.
    But both values are same
    Please anybody helpe me how to compare these values in if condition
    Thanks
    MerlinRosina

    if ((pre_date==sysdat)) is wrong
    U need to use pre_date.equals(sysdat)

  • How to display only Day value instead of DATE in Bex Report

    Hi Experts,
    We have a Month to date Report, in this report we need to display only day value instead of DATE value,
    Like
    if Date is 14.05.2010 we need to show only  14
    Regards,
    Chandra

    Hi ,
    Thanks for Quick Response
    we does have the option to create the char(calday or ...) value variable replacement with char (calday or ...) info object, we can  replace with Report r variable value only not with info object.
    i hope we can replace the with info object only with formula variable with replacement.
    My BEx Report is Designed like
    Columns
    0Calday
    Rows
    Plant
    Keyfigures
    Actual
    Plan
    Report output Looks like month to date
    0CALDAY            01.06.2010   02.06.2010  03.06.2010
    P1  ACTUAL            10                     8                    4
    P1  PLAN                 15                     6                    2
    P2  ACTUAL              5                   10                     7
    P2  PLAN                  4                      8                    3
    Report should be
    0CALDAY            1    2     3
    P1  ACTUAL      10     8      4
    P1  PLAN           15     6     2
    P2  ACTUAL        5    10    7
    P2  PLAN            4      8     3
    please let me know how can i achive this
    Regards
    Chandra

  • How to cell register the date/time when you put a value in another cell

    Hello guys!
    How do I get a cell (eg A2) tell the date and time when I put a value in another cell (eg A1) in Numbers?
    For example, I want to register a cell to read my electricity meter.
    I write in cell A1: 45809. When placing this value in A1, I want to appear (on A2) the date and time when I did that record automatically. Is it possible?
    I hope you understood the question!
    Thank you in advance to those who try to help.

    There is not automatic time stamping of on entry of a time.  One suggestion I've seen has a cell that has the current date and time.  Everytime you cahnge any cell that cell will update.  You can then copy that cell and paste the value into your date/time cell adjacent to the meter reading:
    Create a new, plain table:
    Now in cell A1 enter the formula "=now()"  short hand for this is:
    A1=now()
    now resize the table so it is a table that is 1 cell by 1 cell by selecting any cell, then dragging the table size control in the bottom right corrner towards cell A1:
    It should look like this when you have completed this task:
    Now create another new, plain table and enter "Date" for cell A1, and "Meter Reading" for B1:
    Now you can enter a meter reading (I entered "45671").  Now select the CELL that has current date and time from the first table at the very top, and copy:
    Now select the cell in the date column where you want to put the current date and paste values by using the menu item "Edit > Paste Value":

  • How to add get Day value in a Date object?

    Hi,
    I am writing a sql statement that has two date values. One I am getting it from the database. The format in the database is MM/DD/YYYY. My first question is how do I convert the format into the java date format, YYYY-MM-DD. The second question is I need to find out what the day is and add 1 to it. How do I get Day value in a Date object?
    Thanks.

    Look at "SimpleDateFormat" and "parse" in the archives.

  • Insert a value of type Date/Time into a database

    I am trying to insert a value of type date time into an access database. What is the format needed to insert the date/time.
    Thanks,
    -Amos

    I had all kinds of problems getting a datetime inserted into a SQl Server DB. Probably similar so this is what I do:
    String date = new String("01/01/97 12:00:00");
    stmt.setObject(1, date);
    I tried using TimeStamp's but found I got an occasional Fractional Truncation exception back from the driver. Never had a problem inserting a String using the setObject() method though.
    Hope this helps

  • Can I convert Facebook time Text to Project Siena's Date value ?

    Can I convert Facebook time Text to Project Siena's Date value ?
    I want to show create_time on screen by my Localtime formatted text.
    Facebook time Text = 2014-07-14T11:22+0000
    I want to show = 2014/07/14 18:22
    My Time Zone is +09:00, Osaka/Japan.
    Currently I try it by Text/Replace/Replace/Replace/Left/DateValue/+ , etc.
    And I ask more simple way.
    Regards,
    Yoshihiro Kawabata

    Thank you Andy , and Robin, I can.
    Text(TimeValue(Substitute(ThisItem!created_time,"+0000",".000Z")),"yyyy/mm/dd hh:mm")
    At Facebook Albums's Gallary, I can convert from Facebook created_time to Localtime Text DateTime.
    and I hope more easy way like Excel Power Query's one.
    Regards,
    Yoshihiro Kawabata

  • Can I convert Twitter time Text to Project Siena's Date Value ?

    Can I convert Twitter time Text to Project Siena's Date Value ?
    I want to show localtime of Twitter created_at.
    Twitter time text = ThisItem!created_at , ex: Tue Jul 15 17:19:00 +0000 2014
    I want to show 2014/07/16 02:19 by Japan localtime.
    Regards,
    Yoshihiro Kawabata

    Siena uses JavaScript to parse date/times, via the TimeValue function. A good specification regarding what is acceptable can be found here:
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse
    The example above is truly bizarre: I thought I had seen it all. You will need to turn that form into one of those listed on the above site, using string functions to chop it up and reassemble it into a saner form.

  • Check Data Values, Generates Navigation Data steps taking more time

    Hi,
    In the Masterdata load to 0MAT_PLANT
    The step - "Updating attributes for InfoObject 0MAT_PLANT" used to take a Maximum if 23 minutes for a data package size of 100,000 records till three days ago with the constituent steps "Check Data Values","Process Time-Independent Attributes" and "Generates Navigation Data" taking 5,4 and 12 minutes respectively.
    For the last three days the step "Updating attributes for InfoObject 0MAT_PLANT" is taking 58-60 minutes for the same for data package size of 100,000 records with the constituent steps "Check Data Values","Process Time-Independent Attributes" and "Generates Navigation Data" taking 12,14 and 22 minutes respectively.
    Can anyone please explain what is needed to speeden the dataload back to its previous timing e.g. if  tables indexes need to built for 'P' or 'SID' table of Mat_plant.
    An explanation of why the delay could be happening in the above steps will be really great.
    regards,
    Kulmohan

    Hi Kulmohan Singh,
    I think there may be a difference between the first update and second update is the 100,000 records is
    already in your 0MAT_PLANT.
    If you update the 0MAT_PLANT in twice, The Modify statement should loop the Q table of
    0MAT_PLANT that was already have the 100,000 records in it,so the upload speed was slowly.
    Hope it helpful you.
    Regards,
    James.

Maybe you are looking for