Convert date to number

Hello.
I want to convert date field to number. I used TIMESTAMPDIFF(SQL_TSI_DAY, "Invoice date (invoice header)".Date, CURRENT_DATE ) to get number of days from invoice date to current day but this number is treated as date format and I'm not able to make calculation on that number. Any suggestions how to convert this »number« to real number that also calculation would be possible.
Thank you.
Brgds, Luka

Any hint or is not possible as Kishore said....
I would like to sum (grand total) all the days that I get from TIMESTAMPDIFF.
Example:
Invoice nr. Due date TIMESTAMPDIFF(SQL_TSI_DAY, "Invoice due.date (invoice header)".Date, CURRENT_DATE )
201001006978          30.11.2010     44
201001007250          8.12.2010     36
201001007392          15.12.2010     29
201001007735          23.12.2010     21
201001007815          30.12.2010     14
SUM = 144
Brgds,
L

Similar Messages

  • Help needed in converting date to number

    Hi,
    I am trying to execute the below query, its failing with "invalid number" error.
    select * from process_status
    where time_process > to_char('&3','yyyymmdd')
    time_process is the "number" datatype.
    Details:
    SQL> select * from process_status
    2 where time_process > to_char('&3','yyyymmdd');
    Enter value for 3: 01-MAY-09
    old 2: where time_process > to_char('&3','yyyymmdd')
    new 2: where time_process > to_char('01-MAY-09','yyyymmdd')
    where time_process > to_char('01-MAY-09','yyyymmdd')
    ERROR at line 2:
    ORA-01722: invalid number
    If I execute the below query its working fine, I am facing problem only when I pass the date explicitly to the query. Please help me on converting the date to number format.
    select * from etl_process_status
    where time_process > '20090501'
    and rownum < 3;
    Thanks

    as others have said, it would be best to have your time_process column stored as a date in oracle, if it contains dates.
    The reason for this is because if you store your dates as a number, you have removed information from Oracle that says "This is a date", so when Oracle comes to try and estimate the number of rows greater than a specific value, it can no longer guess correctly, since it's basing its guess on that column being a number.
    There are lots more numbers between '20091201' and '20091101' than there are days between 1st November and 1st December.
    By hiding the fact that your data is a date, you could throw your execution plan off and end up with sub-optimal performance.
    In short, store your data in the correct column format!

  • How to convert date to number

    Hai
    How to convert the given date into number.
    Thanks & regards
    srikkanth.M

    Look at these posts
    Please help me in Converting Lilian Format to Date
    converstion to date
    and try something like this.
    SELECT sysdate,sysdate-to_date('15-10-1582','DD-MM-YYYY') lilian_dt FROM dual;

  • Date to number conversion?

    I want to select a number of rows created within last week.
    To do it I use a select statement with:
    WHERE sysdate-o.created_on <= days;
    (days is a number, created_on is a date)
    Everything works fine, but I get warnings like this one:
    PLW-07204: conversion away from column type may result in sub-optimal query plan
    I suppose I should convert date to number to get rid of them. How can I do it isnide a SELECT query?

    While the comments regarding re-writting the query to allow the possibility of index usage are valid, the warning will still appear even with the re-written query. I am sure that this query would use an index on dt1 if one was available.
    SQL>CREATE TABLE t (id number, dt1 date, dt2 date);
    Table created.
    SQL> CREATE PROCEDURE p1 AS
      2  BEGIN
      3     FOR r IN (SELECT * FROM t
      4               WHERE dt1 = sysdate - 7) LOOP
      5        NULL;
      6     END LOOP;
      7  END;
      8  /
    SQL>/
    SP2-0804: Procedure created with compilation warnings
    SQL>show error
    Errors for PROCEDURE P1:
    LINE/COL ERROR
    3/13     PLW-07204: conversion away from column type may result in
             sub-optimal query planThe warning in this case is clearly spurious, and the reason is, at the level the compiler is looking, they are different data types. dt1 was inserted as sysdate a few minutes before I did the dunp below.
    SQL> SELECT DUMP(dt1) tab_date, DUMP(dt1 - 3) calc_date,
      2         DUMP(sysdate) sys_date
      3  FROM t;
    TAB_DATE                            CALC_DATE                          SYS_DATE
    Typ=12 Len=7: 120,107,2,27,10,45,42 Typ=13 Len=8: 7,215,2,24,9,44,41,0  Typ=13 Len=8: 7,215,2,27,9,49,13,0A date field in a table is a type 12 while sysdate, and any date that has is a result of a calculation is a type 13. Clearly a "different" datatype.
    Practically speaking, in the SQL engine, the type 13 date would be cast to a type 12 date and used in an index probe, but the compiler is likely doing something similar to the DUMP conparision.
    I believe that the type 13 dates are a representation of the C time_t struct that Oracle's kernel would likely use internally.
    John

  • Convert from date to number

    Hi,
    I want to convert from date to number. How can I do?
    Thanks
    [email protected]

    That rather depends on what sort of number you want.
    You can probably get what you want by a combination of to_char and to_number.

  • Function to convert string to number

    Hi there,
    I wrote a function which converted a hor minute component of a date to a number. Now I need to do the same with a string (because the hours could be more then 23:95). Anyway here is my function. How can I rewrite it so it will accept a string as in parameter. Somwhow I can not work it out. Thanks a lot.
    Chris
    function calculate_hours_project(in_hours in DATE)
    RETURN number
    AS
    hrs CHAR(2);
    mins CHAR(2);
         BEGIN
              hrs := to_char(in_day, 'HH24');
              mins := to_char(in_day, 'MI');
              if hrs is not null and mins is not null then
              RETURN to_number(hrs + (mins/60));
              else
              RETURN 0;
              end if;
    END calculate_hours_project;

    Wouldn't it just be something like this?
    sql>create or replace function calculate_hours_project(in_hours in varchar2)
      2  return number
      3  is
      4  begin
      5    return to_number(substr(in_hours, 1, instr(in_hours, ':') - 1)) +
      6           to_number(substr(in_hours, instr(in_hours, ':') + 1) / 60);
      7  end calculate_hours_project;
      8  /
    Function created.
    sql>select calculate_hours_project('08:05') from dual;
    CALCULATE_HOURS_PROJECT('08:05')
                           8.0833333
    1 row selected.
    sql>select calculate_hours_project('35:34') from dual;
    CALCULATE_HOURS_PROJECT('35:34')
                           35.566667
    1 row selected.

  • What is the best way to load and convert data from a flat file?

    Hi,
    I want to load data from a flat file, convert dates, numbers and some fields with custom logic (e.g. 0,1 into N,Y) to the correct format.
    The rows where all to_number, to_date and custom conversions succeed should go into table STG_OK. If some conversion fails (due to an illegal format in the flat file), those rows (where the conversion raises some exception) should go into table STG_ERR.
    What is the best and easiest way to archive this?
    Thanks,
    Carsten.

    Hi,
    thanks for your answers so far!
    I gave them a thought and came up with two different alternatives:
    Alternative 1
    I load the data from the flat file into a staging table using sqlldr. I convert the data to the target format using sqlldr expressions.
    The columns of the staging table have the target format (date, number).
    The rows that cannot be loaded go into a bad file. I manually load the data from the bad file (without any conversion) into the error table.
    Alternative 2
    The columns of the staging table are all of type varchar2 regardless of the target format.
    I define data rules for all columns that require a later conversion.
    I load the data from the flat file into the staging table using external table or sqlldr without any data conversion.
    The rows that cannot be loaded go automatically into the error table.
    When I read the data from the staging table, I can safely convert it since it is already checked by the rules.
    What I dislike in alternative 1 is that I manually have to create a second file and a second mapping (ok, I can automate this using OMB*Plus).
    Further, I would prefer using expressions in the mapping for converting the data.
    What I dislike in alternative 2 is that I have to create a data rule and a conversion expression and then keep the data rule and the conversion expression in sync (in case of changes of the file format).
    I also would prefer to have the data in the staging table in the target format. Well, I might load it into a second staging table with columns having the target format. But that's another mapping and a lot of i/o.
    As far as I know I need the data quality option for using data rules, is that true?
    Is there another alternative without any of these drawbacks?
    Otherwise I think I will go for alternative 1.
    Thanks,
    Carsten.

  • How can I convert date in FOX (from DEC to date[DEC])

    Hi everyone!
    In my planning layout I have a field called "MYDATE" of the date-type "DEC: Calculation or amount field with comma and +/- sign" (-> BPS does not allow using DATS as date-type).
    Since I import that date from a different system, I have to use a temporary workaround field "WADATE" (WorkaroundDate) of type DEC (alternatively integer or float) which contains the date in a format YYYYMMDD (e.g. 20070604).
    How can I transfer the date from WADATE to MYDATE? I tried using FOX, but for some reason it does not work. When I use the following function, MYDATE remains empty:
    DATA TMPDATE TYPE F.
    DATA MYPROJECTS TYPE B906_PROJ.
    FOREACH MYPROJECTS.
    "MYDATE" is the field I want my date in
    "WADATE" is my workaround field that contains the date
    TMPDATE = {WADATE,000,0000000001,0000000001,001}.
    BREAK-POINT.
    {MYDATE,000,0000000001,0000000001,001} = TMPDATE.
    ENDFOR.
    Is it possible to solve my problem with FOX? Or do I have to work with an EXIT function?
    Best regards, Daniel

    Daniel,
    The better approach is the one Marc said but if you have tomake a work around work, I think you might need to try and define your temporary date variable as String and another for the converted date as of type of the final date.  I would not define any date type as float unless you can have part days and it is very important to have part days, integer might work by I would try String first myself.
    It has been a while but on a BW 3.5 project I had to do some manipulation to read the attribute value of material master data to get the launch date and use it to derive the start period (definited as type 0FISCPER) and proportion of month based on number of days remaining after launch date vs the # of days for the month.  I think I used string type function in FOX to derive some of the component...
    Hope this helps,
    mary

  • Is there a way to convert skype online number cont...

    That was the general question, and here are my details:
    I have had a skype number for many years and it was great, around $5.5 a month to call all phones in North America from my laptop from any place in the world with internet. With time, I had a ccumulated a relatively large number of contacts (name of person or party & their phone number(s)). Now I decided that I finally need a regular "smart" cellphone with an AT &T 10c/minute and no data (that's the only way that I understand is not a rip-off, I'm counting on my really unlimited mobile hotspot to get wifi). Now, the company will have me purchase minutes every 30 days which doesn't look very bad considering that I don't have my wifi all the time.
    The problem I'm having is, how to transfer or convert the name/number list on skype to name/number list on my phone? so I can call the same numbers I used to call on slype with my AT&T minutes?
    Typing the numbers one-by-one to my phone may take days!! so, I figured out that there must be away to do it automatically, rather than manually.
    Any help is very appreciated

    Is there any answer skype people?????
    please!

  • Saving result from sp_executesql into a variable and using dynamic column name - getting error "Error converting data type varchar to numeric"

    Im getting an error when running a procedure that includes this code.
    I need to select from a dynamic column name and save the result in a variable, but seem to be having trouble with the values being fed to sp_executesql
    DECLARE @retval AS DECIMAL(12,2)
    DECLARE @MonthVal VARCHAR(20), @SpreadKeyVal INT
    DECLARE @sqlcmd AS NVARCHAR(150)
    DECLARE @paramdef NVARCHAR(150)
    SET @MonthVal = 'Month' + CAST(@MonthNumber AS VARCHAR(2) );
    SET @SpreadKeyVal = @SpreadKey; --CAST(@SpreadKey AS VARCHAR(10) );
    SET @sqlcmd = N' SELECT @retvalout = @MonthVal FROM dbo.CourseSpread WHERE CourseSpreadId = @SpreadKeyVal';
    SET @paramdef = N'@MonthVal VARCHAR(20), @SpreadKeyVal INT, @retvalout DECIMAL(12,2) OUTPUT'
    --default
    SET @retval = 0.0;
    EXECUTE sys.sp_executesql @sqlcmd,@paramdef, @MonthVal = 'Month4',@SpreadKeyVal = 1, @retvalout = @retval OUTPUT;
    SELECT @retval
    DECLARE @return_value DECIMAL(12,2)
    EXEC @return_value = [dbo].[GetSpreadValueByMonthNumber]
    @SpreadKey = 1,
    @MonthNumber = 4
    SELECT 'Return Value' = @return_value
    Msg 8114, Level 16, State 5, Line 1
    Error converting data type varchar to numeric.

    Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need
    to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL. And you need to read and download the PDF for: 
    https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
    >> I need to select from a dynamic column name and save the result in a variable, but seem to be having trouble with the values being fed to sp_executesql <<
    This is so very, very wrong! A column is an attribute of an entity. The idea that you are so screwed up that you have no idea if you want
    the shoe size, the phone number or something else at run time of this entity. 
    In Software Engineering we have a principle called cohesion that says a model should do one and only one task, have one and only one entry point, and one and only one exit point. 
    Hey, on a scale from 1 to 10, what color is your favorite letter of the alphabet? Yes, your mindset is that level of sillyity and absurdity. 
    Do you know that SQL is a declarative language? This family of languages does not use local variables! 
    Now think about “month_val” and what it means. A month is a temporal unit of measurement, so this is as silly as saying “liter_val” in your code. Why did you use “sp_” on a procedure? It has special meaning in T-SQL.  
    Think about how silly this is: 
     SET @month_val = 'Month' + CAST(@month_nbr AS VARCHAR(2));
    We do not do display formatting in a query. This is a violation of at the tiered architecture principle. We have a presentation layer. But more than that, the INTERVAL temporal data type is a {year-month} and never just a month. This is fundamental. 
    We need to see the DDL so we can re-write this mess. Want to fix it or not?
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Conversion failed when converting date and/or time from character string

    Hi experts,
    I'm trying running a query in Microsoft Query but it gives the following error message:
    "conversion failed when converting date and/or time from character string"
    when asks me the data I'm inserting 31-01-2014
    i've copy the query form the forum:
    SELECT T1.CardCode, T1.CardName, T1.CreditLine, T0.RefDate, T0.Ref1 'Document Number',
         CASE  WHEN T0.TransType=13 THEN 'Invoice'
              WHEN T0.TransType=14 THEN 'Credit Note'
              WHEN T0.TransType=30 THEN 'Journal'
              WHEN T0.TransType=24 THEN 'Receipt'
              END AS 'Document Type',
         T0.DueDate, (T0.Debit- T0.Credit) 'Balance'
         ,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')<=-1),0) 'Future'
         ,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>=0 and DateDiff(day, T0.DueDate,'[%1]')<=30),0) 'Current'
         ,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>30 and DateDiff(day, T0.DueDate,'[%1]')<=60),0) '31-60 Days'
         ,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>60 and DateDiff(day, T0.DueDate,'[%1]')<=90),0) '61-90 Days'
         ,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>90 and DateDiff(day, T0.DueDate,'[%1]')<=120),0) '91-120 Days'
         ,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>=121),0) '121+ Days'
    FROM JDT1 T0 INNER JOIN OCRD T1 ON T0.ShortName = T1.CardCode
    WHERE (T0.MthDate IS NULL OR T0.MthDate > ?) AND T0.RefDate <= ? AND T1.CardType = 'C'
    ORDER BY T1.CardCode, T0.DueDate, T0.Ref1

    Hi,
    The above error appears due to date format is differnt from SAP query generator and SQL server.
    So you need convert all date in above query to SQL server required format.
    Try to convert..let me know if not possible.
    Thanks & Regards,
    Nagarajan

  • Convert data in the text file to table in DBL

    Hi guys
    I wanted to convert data in text file which are in multiple rows and columns in DBL format to a table to b seen in labview as DBL format.
    I had tried looking and working at the example but in vain , i just cant produce anything
    pls help. or write me a short example..thanks

    Are you dealing with a table or an array.  For an array, just use the Read spreadsheet file from the File I/O palette.
    For a table,  you will have to convert the number to a string and setting the appropriate precision and width, then write the 2-D string array to the table.
    Message Edited by Ravens Fan on 05-20-2008 11:54 PM
    Attachments:
    Example_VI_BD6.png ‏3 KB

  • How to convert Date in varchar(50) format MM/DD/YYYY HH:MM into YYYY-MM-DD format using MS SQLServer 2008 R2 ?

    Hi,
    I am getting the error "The conversion of a varchar data type to a datetime data type resulted in an out-of-range value."
    when converting date in format Date in varchar(50) format MM/DD/YYYY HH:MM into YYYY-MM-DD format using MS SQLServer 2008 R2.
    Please note that the date in column is Date(varchar(50), null).
    I used the following syntax:
    SELECT  CONVERT(VARCHAR(10), Date, 102) AS Day
    FROM   dbo.[RCap_2G MM/Operator]
    WHERE  (CONVERT(VARCHAR(10), Date, 102) > { fn NOW() } - 1)

    As noted above, either use ISDATE or TRY_CONVERT with the correct conversion style number:
    -- SQL Server 2012 code
    DECLARE @Date varchar(50) = '10/23/2006 10:20';
    SELECT TRY_CONVERT(DATE, @Date, 101) AS Day
    -- 2006-10-23
    Datetime conversion blog:
    http://www.sqlusa.com/bestpractices/datetimeconversion/
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Design & Programming
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • Reg: Convert Data in LSMW

    Hi,
    Upload Purchase Order data using multiple flat file through LSMW
    in LSMW it's working fine upto Display Read Data.
    After that enter into the convert Data it will ask the Transaction Number.
    I didn't understand what's related Transaction Number.
    I tried to enter the some values it will show the error like "Use Date format in the user master". After that i tried to enter the date formate but it's not working and shows blank .
    Please anybody help me regarding this transaction number
    Thanks & Regards.
    Edited by: Praveen SatyaSai on Dec 28, 2011 3:28 PM

    If you leave it empty, all your records will be converted. If you enter 1, the first set of records (or transaction) will be converted.
    basically, you can use it to only convert a specific set of data (or transaction).

  • HOW TO CONVERT DATE INTO NUMBERS

    HI,
    what the syntax for converting date into No. Ex from the first date of the month till current date how many days are there, this No of days needs to be divided by the net sale of the month.
    i have searched in formulas fields but i am not able to find such option...
    please help.
    Thanking you,
    UMAR NAYAB.

    Hi,
    Stratos and Sastry
    the formula given by you shows the variation for the current month of suppose 30 days
    but if the month is of 31 days or 28 days (feb) how will the system will able to generate the report accordingly.
    i want to make a report in which it should show the net sales by the current month and current date.
    so the system should automated by the number of days in a month.
    thanking you..
    UMAR NAYAB.

Maybe you are looking for