Convert Date function to oracle

The follwoing Sql for Sqlserver, what is the equivalent function in oracle. Need help on this.
YTD:
YOUR_DATE_FIELD between DATEADD(yy,
DATEDIFF(yy,0,@Prompt('BEGIN_DATE','D',,mono,free)), 0) AND
@Prompt('END_DATE','D',,mono,free)
MTD:
YOUR_DATE_FIELD between DATEADD(mm, DATEDIFF(mm, 0,
,@Prompt('BEGIN_DATE','D',,mono,free)), 0) AND
@Prompt('END_DATE','D',,mono,free)
WTD
YOUR_DATE_FIELD between (,@Prompt('BEGIN_DATE','D',,mono,free) -
DATEPART(dw, ,@Prompt('BEGIN_DATE','D',,mono,free)))+1 AND
@Prompt('END_DATE','D',,mono,free)

Extracting month,year,day from sysdate (You may even opt to use to_char)
SQL> select extract (month from sysdate) from dual;
EXTRACT(MONTHFROMSYSDATE)
                        4
SQL> select extract (year from sysdate) from dual;
EXTRACT(YEARFROMSYSDATE)
                    2007
SQL> select extract (day from sysdate) from dual;
EXTRACT(DAYFROMSYSDATE)
                      5
Adding 5 days to today's date
SQL> select sysdate + 5 from dual;
SYSDATE+5
10-APR-07
Adding Months
SQL> select add_months(sysdate,3) from dual;
ADD_MONTH
05-JUL-07
Date Difference
SQL> select sysdate - to_date('01/04/2007','dd/mm/yyyy') from dual;
SYSDATE-TO_DATE('01/04/2007','DD/MM/YYYY')
                                4.42670139
Date Difference
SQL> select trunc(sysdate) - trunc(to_date('01/04/2007','dd/mm/yyyy')) from dual
TRUNC(SYSDATE)-TRUNC(TO_DATE('01/04/2007','DD/MM/YYYY'))
                                                       4
SQL>

Similar Messages

  • Raw to date function in oracle

    Hi..
    I would like to know the details and usage of Raw to date function in oracle database.Could some one let me know the function details?

    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> set serveroutput on
    SQL> DECLARE
      2   rv RAW(32) := '786B060818023A';
      3   dt DATE := NULL;
      4  BEGIN
      5    dbms_stats.convert_raw_value(rv, dt);
      6    dbms_output.put_line(TO_CHAR(dt, 'DD-MON-YYYY'));
      7  END;
      8  /
    08-JUN-2007
    PL/SQL procedure successfully completed.
    SQL>Regards,
    Jo
    PS: This is not my own example. I don't recollect the link I got this example from. Will post the link if I come across it again. I think its www.psoug.org (not sure)

  • Convert Data type from Oracle Data time string to SQL Date time data type

    I have a time stamp column pulled from oracle into a SQL server db table varchar datatype column.
    Now i want to change that column to date time.
    Following is the data present in the table:
    01-APR-11 02.15.00.026000 AM -08:00
    01-APR-11 04.15.00.399000 AM -08:00
    01-APR-11 06.15.00.039000 AM -08:00
    I want to convert this data into sql server datetime data type.
    Please advice.
    Thanks,
    Sam.
    I am unable to find the solution in other sites which is why I have posted it in Oracle forum for seeking solution.
    Thanks in Advance.
    Sam.

    Sam,
    How are you actually loading the data into SQL*Server - are you using something like an Oracle gateway, BCP or another Microsoft utility of some sort ?
    If you are using an Oracle problem then we may be able to help but if using a Microsoft utility then you should really follow up with Microsoft to know what format the data should be in to use a Microsoft utility.
    Regards,
    Mike

  • Date functions in Oracle 8i Lite

    When i am trying to type in the following command in my win98 o/s:
    select to_char(to_date('01-jul-1997','dd-mon-yyyy'),'day ww')from dual
    My sql*plus returns the following error message:
    OCA-30021: error preparing/executing SQL statement
    [POL-2423] invalid value for date/time field
    However, I can run this statement under the 8i lite WINNT environment. I want to know whether this is due to limitation of 8i lite running on Win98 or there is some problem with my configuration of Oracle 8i?
    null

    This syntax doesn't work.Do you mean it hurls an exception or just doesn't return the expected result? Please describe the expected and actual behaviour, with error messages if appropriate. Because it ought to work...
    SQL> select * from dds;
            ID SDATE     EDATE
             1 11-FEB-06 11-MAR-06
             2 06-APR-06 11-APR-06
             3 11-APR-06 11-MAY-06
    SQL> set serveroutput on
    SQL> declare
      2    d1 date := trunc(sysdate, 'MM');
      3    d2 date := last_day(sysdate);
      4  begin
      5    for r in ( select * from dds
      6               where sdate >= d1 and edate <= d2 )
      7    loop
      8       dbms_output.put_line(r.id||'::'||r.sdate||'::'||r.edate);
      9    end loop;
    10  end;
    11  /
    2::06-APR-06::11-APR-06
    PL/SQL procedure successfully completed.
    SQL> Cheers, APC

  • Date functions in Oracle

    Hello
    I need to rewrite the following sql I used in MSSQL server to sql for Oracle:
    declare @lastmo_start datetime,
         @lastmo_end datetime
    select @lastmo_start = dateadd(month, -1, getdate())
    select @lastmo_end= dateadd(day, -1, getdate())
    Basically I need to declare 2 variables and then set those values to the first day of the month and the last day of the same month.I will use these variables later in my script.
    How I can do this in Oracle?
    Thank you,
    Lena

    This syntax doesn't work.Do you mean it hurls an exception or just doesn't return the expected result? Please describe the expected and actual behaviour, with error messages if appropriate. Because it ought to work...
    SQL> select * from dds;
            ID SDATE     EDATE
             1 11-FEB-06 11-MAR-06
             2 06-APR-06 11-APR-06
             3 11-APR-06 11-MAY-06
    SQL> set serveroutput on
    SQL> declare
      2    d1 date := trunc(sysdate, 'MM');
      3    d2 date := last_day(sysdate);
      4  begin
      5    for r in ( select * from dds
      6               where sdate >= d1 and edate <= d2 )
      7    loop
      8       dbms_output.put_line(r.id||'::'||r.sdate||'::'||r.edate);
      9    end loop;
    10  end;
    11  /
    2::06-APR-06::11-APR-06
    PL/SQL procedure successfully completed.
    SQL> Cheers, APC

  • Converting Stuff function from SQLServer to Oracle

    Anyone out there found an Oracle counterpart for the SQL Server "stuff" function.
    It is being used following an ascii(substr(variable)) locating all nonprintable characters and replacing with null.

    anjali5 wrote:
    I am very new to oracle. I am trying to convert this function to oracle, but keep getting errors
    USE [REF]
    GO
    /****** Object: UserDefinedFunction [dbo].[fnc_get_home] Script Date: 10/21/2011 17:50:10 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    -- =============================================
    -- Author:          <Author,,Name>
    -- Create date: <Create Date, ,>
    -- Description:     <Description, ,>
    -- =============================================
    ALTER FUNCTION [dbo].[fnc_get_home]
         @p_ui nvarchar(50), @p_dt datetime
    RETURNS NVARCHAR(50)
    AS
    BEGIN
         declare @v_home NVARCHAR(50);
         select top 1 @v_home = HOME_CODE from dbo.activity_home_b
              where UI = @p_ui
              order by HOME_END_DT desc;
         RETURN @v_home;
    ENDI am very new to Volkwagen cars, but here is a picture of my old Toyota
    My new car won't go
    Tell me how to make my car go.
    You refer to Oracle, but I wonder if this has anything to do with ACCESS.
    post complete CREATE TABLE statement of Oracle Table
    post INSERT for sample test date & expected/desired results

  • SQL Devloper Migration from SQL SerProcedurs created as Functions in Oracle

    Hi All,
    This is the first time I am using SQL Deveoper to migrate SQL Server database to Oracle.
    I have SQL Developer 3 and I did migration from SQL Sever 2008 to Oracle 10g using online migration.
    Everything was done perfectly, but there are some extra tables created in Oracle which are not present in SQL Server database.
    And also I observed lot of programs which are stored procedures in SQL Server are converted as functions in Oracle.
    Does someone knows how to fix this problem.
    Thanks

    Hi,
    A SQL*Server stored procedure can be converted to an Oracle function depending on how it is written and what it is doing. In the documentation -
    Oracle® SQL Developer
    Supplementary Information for Microsoft SQL Server and
    Sybase Adaptive Server Migrations
    In Chapter 3 in the section -
    3.4.2 Function
    It says under Table 3-6 -
    In Microsoft SQL Server or Sybase
    Adaptive Server, you can convert a stored
    procedure to a function in Oracle because
    the stored procedure in Microsoft SQL
    Server or Sybase Adaptive Server can
    RETURN an integer value to the calling
    routine using a RETURN statement. A
    stored procedure returns a status value to
    the calling routine even in the absence of
    a RETURN statement. The returned status
    is equal to ZERO if the procedure
    execution is successful or NON-ZERO if
    the procedure fails for some reason. The
    RETURN statement can return only
    integer values
    And what tables do you see in oracle that are not there in SQL*Server ? Some tables are created as part of the migration as they are needed to have the same functionality as in SQL*Server.
    Does your migrated Oracle database work in the same way as the SQL*Server database ? If not, then please give use specific examples and we can follow up.
    Regards,
    Mike

  • Imbed Date Function????

    Hi,
    I am having trouble with a date function in Oracle Administrator. How do I make max_date a condition (for a case statement)? I am trying to return a value (a ranking) for the most recent ranking date.
    Ie:
    Case
    When Date = Max --I know you can use a Max(date) function but 
    and (another condition) --how do you make that a condition within case
    Then (return value) -- statement?
    Else 0
    End
    Is this a case where I have to import an Oracle Function? Or can I get around this by using a pre-existing function?

    Multiple posting
    Date Function - Holiday?

  • Converting numeric date (seconds) to Oracle date

    Hello all,
    Not sure if this is the correct place for my question but here goes...
    I am extracting data from an Oracle table in which the date/time is stored as a number (seconds since 1970). How can I convert this to an Oracle recognized date? I tried to extract the date as a number and then convert it using the localtime function in PERL but ran into other problems. Any help or advice would be greatly appreciated.
    David

    Instead of writing PERL script if you write on a format trigger same coad (using Pl/SQL) it will work.

  • How to I convert data from oracle database into excel sheet

    how to I convert data from oracle database into excel sheet.
    I need to import columns and there datas from oracle database to microsoft excel sheet.
    Please let me know the different ways for doing this.
    Thanks.

    asktom.oracle.com has an excellent article on writing a PL/SQL procedure that dumps data to an Excel spreadsheet-- search for 'Excel' and it'll come up.
    You can also use your favorite connection protocol (ODBC, OLE DB, etc) to connect from Excel to Oracle and pull the data out that way.
    Justin

  • How to convert date format to ISO8601 in Oracle BPEL

    Hi,
    I need to convert date format from YYYY/MM/DD 00:00:00 to YYYY-MM-DDThh:mm:ss format in oracle BPEL. Can any of you help me out. Thanks in advance.

    Hi Anuj,
    I have use the below mentioned code to convert the date format.
    <db:P_X_DATE_FROM>
    <xsl:value-of select='concat(substring(../VALUE,1.0,4.0),"-",substring(../VALUE,6.0,2.0),"-",substring(../VALUE,9.0,2.0),"T",substring(../VALUE,12.0,8.0))'/>
    </db:P_X_DATE_FROM>
    Thanks & Regards,
    Jyotirmoy.

  • I want convert string to date format in Oracle

    Dear All
    I want convert string to date format in Oracle,Format is given below
    'Friday, 02 March 2012 2:44 PM' to '02/03/2012 2:44 PM'

    >
    Hi Parwez,
    I want convert string to date format in Oracle,Format is given below
    'Friday, 02 March 2012 2:44 PM' to '02/03/2012 2:44 PM'SELECT TO_DATE('Friday, 02 March 2012 2:44 P.M.', 'DAY, DD MONTH YYYY HH:MI A.M.') from dual;
    As well as what the other poster suggested, look here: http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements004.htm#i34924
    HTH,
    Paul...

  • Function module to convert date form yyyy/mm/dd to dd/mm/yyyy format

    Can any one tell me Function module to convert date form yyyy/mm/dd to dd/mm/yyyy format?

    have a look at the WIKI FAQs...they are very useful
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/abap/abapDevelopmentand+Programming&
    For this it says:
    <i>How to convert a date to internal or external format?
    Use the functions modules CONVERT_DATE_TO_EXTERNAL or CONVERT_DATE_TO_INTERNAL
    to convert the date. When converting to external format, the date format from the user's user profile will be used. When converting to internal format, the result will be in YYYYMMDD format.</i>

  • FUNCTION MODULE TO CONVERT DATE / TIME INTO WORDS.

    HI EXPERTS,
         FUNCTION MODULE TO CONVERT DATE / TIME INTO WORDS.
    PLS DO HELP.....

    Hiii gita
    we have another FM SPELL_AMOUNT
    regards
    Jaipal

  • Function module to convert date format from yyyymmdd to mmddyyyy format

    function module to convert date format from yyyymmdd to mmddyyyy format

    Hi Rajitha,
    Do like this
    Data: Var1 type sy-datum,
             var2(8) type c.
    var1 = sy-datum.
    Concatanate var1+4(2) var1+6(2) var1+0(4) into var2.
    write var2.
    Reward Points if this helps,
    Satish

Maybe you are looking for

  • AVCHD - best definition to export

    What's the best options to export my projects from FCE? Share using Quicktime? And the best settings? All my clips are full HD quality and I don't wanna loose this great image quality, I'd like to export and keep the same quality as a raw footage (wh

  • Exception occured in the log while rendering portlets on the page.

    Hi Experts I am getting following error, While my page is getting rendered with all the portlets: Could you please let me know, How can handle this exception? <PortletResourceServlet> <_process> Error proxying resource. oracle.portlet.client.containe

  • How to view my pictures on my Televison

    I can plug my phone into Xbox and view my pictures anymore. Why?

  • Can't tell what generation ipod shuffle I have

    I've looked at the online community for I-pod shuffle's link and still can't tell what generation I have.  My last 3 serial numbers aren't numbers they are letters. Any help? Thanks

  • Security using Maxl Script

    I need to give security for a folder using Maxlscript/Bach filesl.Is it possile.......?