( Urgent ) Date Formatting

I want to know how to get a date value with Milliseconds by using Date Format or any.
For Eg: I am having a LOG( Transactions) table wherein I have a date_create column of a DATE Datatype.
I want to get( Display or retrieve) the value in Milliseconds after formatting. Is there anyway out.
Does ORACLE provide that..
Thanks in Advance for your Response..
null

2 solutions:
1) write a java stored procedure. java has time functionality
that is much more granular then the Oracle DATE type. This will
work in 8.1.5 and up. It can look like this:
[email protected]> CREATE or replace JAVA SOURCE
2 NAMED "MyTimestamp"
3 AS
4 import java.lang.String;
5 import java.sql.Timestamp;
6
7 public class MyTimestamp
8 {
9 public static String getTimestamp()
10 {
11 return (new
12 Timestamp(System.currentTimeMillis())).toString();
13 }
14 };
15 /
Java created.
[email protected]> create or replace function my_timestamp
return varchar2
2 AS LANGUAGE JAVA
3 NAME 'MyTimestamp.getTimestamp() return java.lang.String';
4 /
Function created.
[email protected]> l
1* select my_timestamp, to_char(sysdate,'yyyy-mm-dd
hh24:mi:ss') from dual
[email protected]> /
MY_TIMESTAMP
TO_CHAR(SYSDATE,'YY
2000-06-22 13:47:53.376
2000-06-22 13:47:53
[email protected]>
2) use an external procedure written in C. C has api's to the
system that allow for much more granular time components. This
will work in 8.0 and up. For example if you run something like:
[email protected]> create or replace library timelib as
2 '/export/home/tkyte/src/t/extproc.so'
3 /
Library created.
[email protected]> create or replace
2 procedure get_extended_time( p_timestring out varchar2 )
3 is external
4 name "get_extended_time"
5 library timelib
6 language C
7 with context
8 parameters ( CONTEXT,
9 p_timestring STRING,
10 p_timestring INDICATOR short,
11 p_timestring MAXLEN int,
12 p_timestring LENGTH int );
13
14 /
Procedure created.
[email protected]> declare
2 l_timestring varchar2(30);
3 begin
4 get_extended_time( l_timestring );
5 dbms_output.put_line(
to_char( sysdate, 'mm/dd/yy hh24:mi:ss' ) );
6 dbms_output.put_line( l_timestring );
7 end;
8 /
06/22/00 13:26:28
06/22/00 13:26:28.103243
PL/SQL procedure successfully completed.
In sqlplus after compiling the following C code into a .so or
.dll or .sl (depending on platform) you can get the
milliseconds.
Here is the C code:
#include <stdio.h>
#include <stdarg.h>
#include <time.h>
#ifndef OCI_ORACLE
# include <oci.h>
#endif
#define raise_application_error return raise_application_error_x
static long raise_application_error_x( OCIExtProcContext * ctx,
int errCode,
char * errMsg, ...)
char msg[8192];
va_list ap;
va_start(ap,errMsg);
vsprintf( msg, errMsg, ap );
va_end(ap);
OCIExtProcRaiseExcpWithMsg(ctx,errCode,msg,strlen(msg));
return -1;
long
get_extended_time( OCIExtProcContext * ctx,
char * p_data,
short * p_data_i,
int * p_data_maxl,
int * p_data_l )
struct timeval tp;
if ( *p_data_maxl < 25 )
raise_application_error( ctx, 20001,
"String must be 25 bytes or more" );
gettimeofday(&tp, NULL);
cftime( p_data, "%D %T", &tp.tv_sec );
sprintf( p_data+strlen(p_data), ".%d", tp.tv_usec );
*p_data_l = strlen(p_data);
*p_data_i = 0;
return 0;
null

Similar Messages

  • URGENT: Date format in Reports Giving me trouble...plz help me out

    Hi guru's Can any one help me out
    I
    n the front end apps we are getting the date value as
    BOM_SRS_DATETIME_STANDARD
    Where we are entering the date value as MM/DD/RRRR HH24:MI:SS
    The date format set in the company is like RRRR/MM/DD HH24:MI:SS
    SO I format masked the date parameter in .RDF to RRRR/MM/DD HH24:MI:SS format.
    While the actual date format in the data base is like DD/MM/RRRR HH24:MI:SS.
    I checked all the old reports and the date format is like they masked the date format to company format and used the afterparameter trigger like bellow:
    if :P_SENT_DATE_FROM is not null and :P_SENT_DATE_TO is null then
    :P_SENT_DATE_TO := :P_SENT_DATE_FROM;
    end if;
    if (:P_SENT_DATE_FROM = :P_SENT_DATE_TO) and (:P_SENT_DATE_FROM is not null) then
    :WHERE_SQL := :WHERE_SQL || ' AND CREATION_DATE = '||' to_date('''||:P_SENT_DATE_FROM||''''||','||'''DD-MON-RR'')';
    else
    if :P_SENT_DATE_FROM is not null then
    :WHERE_SQL := :WHERE_SQL || ' AND CREATION_DATE >= '||' to_date('''||:P_SENT_DATE_FROM ||''''||','||'''DD-MON-RR'')';
    end if;
    if :P_SENT_DATE_TO is not null then
    :WHERE_SQL := :WHERE_SQL || ' AND CREATION_DATE <= '||' to_date('''||:P_SENT_DATE_TO ||''''||','||'''DD-MON-RR'')';
    end if;
    end if;
    I tried this but i couldnt get the output either.
    I am pretty much confused.
    Plz help me out...

    If you want to use a dynamic where caluse in your report query you can use a Reference Cursor using REF CUR QUERY tool in your report like this :
    function QR_1RefCurDS return DEF_CURSORS.CHARACT_REFCUR is
    temp_CHARACT DEF_CURSORS.CHARACT_refcur;
    begin
    IF :FROM_NO IS NULL AND :TO_NO IS NULL THEN
    open temp_CHARACT for SELECT ACCT_CODE, ACCT_NAME
    FROM CHARACT
    ORDER BY ACCT_CODE;     
    ELSIF :TO_NO IS NULL AND :FROM_NO IS NOT NULL THEN
    open temp_CHARACT for select ACCT_CODE, ACCT_NAME
    FROM CHARACT
    WHERE ACCT_CODE=:FROM_NO
    ORDER BY ACCT_CODE;     
    ELSIF :TO_NO IS NOT NULL AND :FROM_NO IS NOT NULL THEN
    open temp_CHARACT for select ACCT_CODE, ACCT_NAME
    FROM CHARACT
    WHERE ACCT_CODE BETWEEN :FROM_NO AND :TO_NO
    ORDER BY ACCT_CODE;               
    ELSIF :TO_NO IS NOT NULL AND :FROM_NO IS NULL THEN
    open temp_CHARACT for select ACCT_CODE, ACCT_NAME
    FROM CHARACT
    WHERE ACCT_CODE<=:TO_NO
    ORDER BY ACCT_CODE;     
    END IF;
    return temp_CHARACT;
    end;
    But first you have to declare a cursor type in a package

  • Urgent date format problem

    Hi every one
    I have a problem with date format in my database.
    I am using Oracle8 Release 8.0.4.0.0 - Production server.
    Generally all procedures in my application runs with the date format DD-MON-YY
    I dont know suddenly what happens to this format and it changes to YYYY/DD/MM
    and all my procedures will run with the format YYYY/DD/MM then nothing happens in the database.
    Please tell me why this date change happening
    Thanks
    ...

    One possible reason :
    TEST@db102 SQL> select sysdate from dual;
    SYSDATE
    13-AUG-06
    TEST@db102 SQL> exit
    Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    [ora102 ~ db102]$ export NLS_DATE_FORMAT=YYYY/MM/DD
    [ora102 ~ db102]$ sqlplus test/test
    SQL*Plus: Release 10.2.0.1.0 - Production on Sun Aug 13 12:03:19 2006
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    TEST@db102 SQL> select sysdate from dual;
    SYSDATE
    2006/08/13
    TEST@db102 SQL>                                                                                    

  • Urgent: Date format conversion

    Hi
    I need to convert the date from 08/31/2006 to 31-Aug-06 format.
    Plz help me out.  Useful answers will be rewarded.  Thanks in advance.

    Hello,
    Check the table :
    T247
    Check these fm's
    Function Modules related to Date and Time Calculations
    DATE_COMPUTE_DAY  : Returns weekday for a date
    DATE_GET_WEEK  : Returns week for a date
    DAY_ATTRIBUTES_GET  : Returns attributes for a range of dates specified
    MONTHS_BETWEEN_TWO_DATES  : To get the number of months between the two dates.
    END_OF_MONTH_DETERMINE_2  : Determines the End of a Month.
    HR_HK_DIFF_BT_2_DATES  : Find the difference between two dates in years, months and days.
    FIMA_DAYS_AND_MONTHS_AND_YEARS  : Find the difference between two dates in years, months and days.
    MONTH_NAMES_GET  : Get the names of the month
    WEEK_GET_FIRST_DAY  : Get the first day of the week
    HRGPBS_HESA_DATE_FORMAT  : Format the date in dd/mm/yyyy format
    SD_CALC_DURATION_FROM_DATETIME  : Find the difference between two date/time and report the difference in hours
    L_MC_TIME_DIFFERENCE  : Find the time difference between two date/time
    HR_99S_INTERVAL_BETWEEN_DATES  : Difference between two dates in days, weeks, months
    LAST_DAY_OF_MONTHS  : Returns the last day of the month
    Vasanth

  • URGENT !!!!   Problem with Date format MM/DD/YYYY in oracle database to BW

    Hi
    I am wondering if somebody can help me urgently.
    I have oracle database where date is of the format MM/DD/YYYY and I am loading data into BW. DATE data type
    Date in oracle database: 3/30/2007
    First when I used InfoObject ZDATE (with 0DATE) reference (DATS data type) data load failed saying that
    'Value '30-MAR-0 ' of characteristic 0DATE is not a number with 000008 spaces'
    Then I created ZDATE InfoObject as CHAR Type (Length 10) with PDATE Conversion Routine.
    when I created datasource using DB Connect and checked the contents using 'Display Table Contents' after creating data source the data field distorted as
    AR/-0/30-M
    After data load. when I checked PSA
    The Date records look same as AR/-0/30-M
    In cube the field appeared as  30-MAR-0  (last digit of year disappearing)
    In BEx report also it looks like 'AR/-0/30-M'
    Can somebody help me as quickly as possible.
    What should I do if i want to still use DATS data type for ZDATE?
    should I change date format in database if so to what?
    If I should use CHAR type with PDATE or any other routine can somebody give me the routine to have the date in the report exactly as it appears in database?
    I also tried changing date format in user profile...settings. But still its the same.
    Thanks in advance.

    Hello Snrella,
    You can solve this by converting the date format from oracle to the SAP internal date format  using an ABAP routine in the transfer rules.
    Assuming the oracle data field name is ZODATE then here's the ABAP you can use in the transfer rules. Create an ABAP routine transfer rule from ZODATE to your ZDATE infoobject, and then put this ABAP code there. (this code assumes that the format of the date from oracle is MM/DD/YYYY).
    concatenate tran_structure-/BIC/ZODATE+6(4) tran_structure-/BIC/ZODATE(2) tran_structure-/BIC/ZODATE+3(2) into result.
    Hope this helps.

  • Amount and Date Formatting Urgent !!

    Hello Gurus,
    I want to format Amount in the below manner , I need to put this data in a text file ,
    When I read it from SAP , irrespective of whatever format
    I need to write the data in the text file in the following format
    999999999999.999
    if the amount is 12 then
    000000000012.000
    if the amount is 100 then
    000000000100.000
    Also , I need a help on date formating
    My date will always appear in the text file in the following format
    YYYY.MM.DD
    so irrespective of whatever user settings on has I need the format to appear in the text file as above.
    Please help me Points guaranteed , please try it at your end
    and please paste the code.
    rgds,
    Aryan

    Hi Aryan,
    For Amount, try out the below code...it will work fine.
    REPORT  ZAMT_DAT                                .
    TYPES amt   TYPE p DECIMALS 3.
    data : v_amt(16) type c ,
           v_amt1 type amt value 100,
           v_len type i,
           v_len1 type c,
           p_date(10) type c value '23012008'.
           v_amt = v_amt1.
           condense v_amt.
           v_len = strlen( v_amt ).
           v_len = 16 - v_len.
           do v_len times.
           concatenate '0' v_amt into v_amt.
           enddo.
           write : v_amt.
    For date, set the user settings as  below...
    system-userprofile->owndata->defaults->dateformat
    set it to the 4 th radio button....
    it will work fine.
    Thanks

  • Amount and Date Formating Urgent !!

    Hello Gurus,
    I want to format Amount in the below manner , I need to put this data in a text file ,
    When I read it from SAP , irrespective of whatever format
    I need to write the data in the text file in the following format
    999999999999.999
    if the amount is 12 then
    000000000012.000
    if the amount is 100 then
    000000000100.000
    Also , I need a help on date formating
    My date will always appear in the text file in the following format
    YYYY.MM.DD
    so irrespective of whatever user settings on has I need the format to appear in the text file as above.
    Please help me Points guaranteed , please try it at your end
    and please paste the code.
    rgds,
    Aryan

    Hi,
    Try out the following code for obtaining the date in YYYY.MM.DD format.
    data mydate like sy-datum.
    data: year(4) type c,
          month(2) type c,
          date(2) type c.
    year = mydate(4).
    month = mydate+4(2).
    date = mydate+6(2).
    write: / year no-gap, month no-gap, date.

  • URGENT: XML-SQL: Error parsing different date formats in the same XML file.

    Hi Everyone,
    I have a big problem while using the XML-SQL utility. I have a XML file with different date formats. I get exception like the one below.
    "oracle.xml.sql.OracleXMLSQLException: 'java.text.ParseException: Unparseable date:"
    And the XML file is :
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Info Key="ID">
         <Insert>
              <ID>1</ID>
              <BookingDate>10.12.2001</BookingDate>
              <OpeningTime>19:16</OpeningTime>
         </Insert>
    </Info>
    I have tried using different setDateFormat which is contrary.
    sav.setDateFormat("d.M.y");
    sav.setDateFormat("H:m:s");
    Can someone help me on the same.
    Thanks in advance.
    Subramanian.

    You might have to describe the columns as varchar then modify the table to the right format.

  • Urgent ......regarding date format in SAP Script

    In my MAIN WINDOW  I have date fields like Date of Manifacture, created date and Expiry date.
    So, currently  I am using SET DATE MASK = 'YYYY-MM' and it is printing same format for all fields.
    But now my requirement is I want to show date for Expiry Date like 'YYYY-MM-DD'. For this I defined one temparary variable in the form like below
    DEFINE &outdate& = &mchar-vfdat&
    SET &outdate& MASK = 'YYYY-MM-DD'.
    but still it is showing format YYYY-MM...
    Plz help me how to print my desired date format...
    I am waiting for ur reply...
    Regards,
    Kumar

    Hi Kishore kumar,
    What you can do is befor printing the Expiry date set the date Mask as 'YYYY-MM-DD' and after printing your Expiry Date again set the DATE MASK to 'YYYY-MM'
    i.e.
    /: SET DATE MASK = 'YYYY-MM-DD'
       &mchar-vfdat&
    /: SET DATE MASK = 'YYYY-MM'
    Regards,
    Sunil

  • Date format not recognized -- urgent help needed

    Hi,
    I'm having a problem when start sqlplus in dos command window. If I start it from C:\oracle\ora81\bin, it won't started and error message showing like 'Date format not recognized' and then come back to DOS.
    I do have OWB installed which also has SQLPLUS installed so that there is no problem if I start it from C:\ORACLE\owb92\bin.
    For some reason, the path is setting as C:\oracle\ora81\bin before C:\ORACLE\owb92\bin so the default always goes to 81 folder.
    If restart the DB instance, and this problem is gone. But it comes back after some application running (our own application and Oracle provided OMBPlus ). We double check our own application, and there is no where to "alter session ...".
    Any help will be very appreciatged,
    Thanks,
    Daming

    I'm having a problem when start sqlplus in dos command window. If I start it from C:\oracle\ora81\bin, it won't started and error message showing like 'Date format not recognized' and then come back to DOS.
    Do you have a file called 'login.sql' in the folder 'C:\oracle\ora81\bin'? If there is one, is there an 'alter session' command in this file?

  • Problem in date format urgent.

    hi everyone,
    i am developing a report in that i am passind date as DDMMYYYY,  here i am not seeing any output in report that output should be sent to customet trrow mail as excel sheet,
    i am succeded in that but i am getting date format problem.
    that is he want to upload that file into sap, in that that the date format is YYYY / MM / DD. but i am unable to do that.
    i used this stmts for that.
    Concatenate   v_string0(4)  v_string4(2) v_string+6(2)  into v_date SEPARATED BY '/' .
       concatenate  c_equal c_colon v_date c_colon into v_date.
    but it is giving ="YYYY / MM / DD" if i remove the second stmt it is giving DDMMYYYY only can you help me in this issue.
    i need that format as YYYY / MM / DD.like this.
    regards,
    chaithu.p

    Hi,
    Ur v_string = DDMMYYYY  right,
    so use concatenate statement as follows,
    Concatenate v_string4(4)  v_string2(2)  v_string+0(2) into v_date SEPARATED BY '/' .
    concatenate c_equal ` `  v_date into v_date.
    if u don't want '=' also remove that from concatenate statement.
    i think this will give u correct order.
    Regards,
    kk.
    Edited by: kusuma kurapati on May 8, 2008 7:05 AM

  • Date format  urgently

    function module which convert date format in required date format means system date to user friendly like dd.mm.yyyy
    mm/dd/yyyy    yyyy/mm/dd like 8 type..

    Hi,
    You cna use CONVERT_DATE_TO_EXTERNAL
    or you can write these lines in your code to get the user format, this will support all the SAP formats
    DATA: date_1 like sy-datum.
    data: Date2(8).
    data: date_3(10).
    date_1 = SY-DATUM.
    Move DATE_ 1 to DATE_2.
    Write: Date_2 to Date_3.
    Write:/ Date_3.
    so now, Date_3 will have the user format.
    Regards
    Sudheer

  • Date format with alter session -- very urgent !!!!

    The default format of date is DD-MON-YY.
    I like to change as DD/MM/YYYY. So I tried to do so by going
    through my login in SQLPlus and wrote
    ALTER SESSION
    SET NLS_DATE_FORMAT = 'DD/MM/YYYY'.
    The format got changed and there after every query displayed
    date in dd/mm/yyyy format. But once I exit sqlplus and reenter
    in sqlplus, the format goes away and the default date format i.e
    dd-mon-yy comes in existence.
    I want to know, how can i make my date format permanent and too
    for all users.
    null

    hello Khan,
    You can set this format in 2 ways, one is
    local setting and the other one is on server setting.
    Edit your c:\windows\oracle.ini (local setting)
    or your init.ora (oracle server setting)
    and add this script
    SET NLS_DATE_FORMAT = 'DD/MM/YYYY'
    note: if there's no nls_date_format in oracle.ini, the server
    nls_date_format in init.ora will be the current setting
    on your PC
    Hope this will help
    NEC PHIl.
    Shamsad Khan (guest) wrote:
    : The default format of date is DD-MON-YY.
    : I like to change as DD/MM/YYYY. So I tried to do so by going
    : through my login in SQLPlus and wrote
    : ALTER SESSION
    : SET NLS_DATE_FORMAT = 'DD/MM/YYYY'.
    : The format got changed and there after every query displayed
    : date in dd/mm/yyyy format. But once I exit sqlplus and reenter
    : in sqlplus, the format goes away and the default date format
    i.e
    : dd-mon-yy comes in existence.
    : I want to know, how can i make my date format permanent and
    too
    : for all users.
    null

  • Date format, urgent, Please help

    I'm having problem with date format. In the sql I need get data that greater than
    '05-01-2005' but cannot get it work.the = is Ok but not > or >=.
    Could someone please tell why and how to do it?
    Many thanks
    this one is work.
    select distinct to_char(LAST_MODIFIED_DATE, 'DD/MM/YYYY') start_date
    from ccst_acctsys_account
    where to_char(LAST_MODIFIED_DATE,'DD-MM-YYYY') = '05-01-2005';
    this one is not work
    select distinct to_char(LAST_MODIFIED_DATE, 'DD/MM/YYYY') start_date
    from ccst_acctsys_account
    where to_char(LAST_MODIFIED_DATE,'DD-MM-YYYY') > '05-01-2005'

    since you convert the date to character format you won't be able to use the > or <
    you might want to use the trunc() function and convert the '05-01-2005' in date datatype:
      select distinct to_char(LAST_MODIFIED_DATE, 'DD/MM/YYYY') start_date
        from ccst_acctsys_account
       where trunc(LAST_MODIFIED_DATE) >= to_date('05-01-2005','dd-mon-yyyy');Message was edited by:
    Warren Tolentino
    Jonh has the same solution. You might want to try including the TRUNC() function.

  • DATE Format Error in ODI-11g(11.1.1.3)

    I am using ETL transformations in ODI-11g. There's a dominant issue regarding date formattings when I map an ODI variable (storing date) with a TGT column(datatype=date) mappings.
    In all the src-tgt mappings I am formatting the date by using TO_DATE() functions. But still getting the error:
    "ORA-01830: date format picture ends before converting entire input string".
    A point to Note: The same ETL in other env are ruuning fine but in my new dev env it's giving this date error.
    I had checked with the DBA folks and they confirmed they set equal DATE settings in all the env.
    The ODI Variable is defined as an "Alphanumeric".
    Tx Used: #BUSINESS_CURRENT_DT=TO_DATE('Date','YYYY-MM-DD')
    Require some urgent advice...Please let me know

    Hi,
    W store name-value pair in the Control table from where we exctract our data. Both (param name and param value) are varchars.
    Well this looks pretty strange in 11g! Here's what we found out...
    If you are trying to retrieve a date variable by using TO_DATE() in the refresh query the ODI Java driver (JDK 1.6) would call java.sql.timestamp and gracefully attach HH:MI:SS.NS along with the date (YYYY-MM-DD HH:MI:SS.NS). My target ia a date always..!
    So, when I do: TO_DATE('20101010','YYYY-MM-DD) in the refresh query ODI stores it as '2010-10-10 00:00:00.0'
    For this the Load always fails as Oracle would not be able to interpret a timestamp by suing TO_DATE()
    The Java driver does this damage. However, it may be wise to store as a timestamp rather as a date if in case u do a Data capture and want the exact time credentials.
    Unfortunately not a req, as of now for us so I had to chop-off the timestamp..!
    Let me know if you find any other details...
    Thanks.!

Maybe you are looking for

  • Movie bought from itunes in 2008 will no longer play?

    Ok I bought the movie the notebook in 2008. I changed laptops this year and had the tehnician transfer all my files to my new laptop (muisc/videos). Now the movie will not play in itunes or any other music player. The video player comes up, but the s

  • Error in User Management Link CRM 7.0

    Hi As per CRM 7.0 standard functionality (with ECC as a back end), USER MANAGEMENT Link is available to maintain WEBSHOP Logon users. We are getting the below error when we try to maintain the USERS through that link "SERIAL NUMBER MISSING u2013 ENTR

  • If your ipod shuffle won't respond read this it might help

    Hi I got this from the apple help line. It fixed my ipod shuffle. I hope it helps. My ipod had music on it and was recognized by the computer and itunes, it just wouldn't play anything and the green light just stayed on. I was using windows xp If tha

  • Error msg when I try to import, orig files deleted. Pls help!

    moved files out-cant import them back orginal files deleted. Helpp!!!

  • MIGO : CHANGE FIELD STATUS FROM DISPLAY TO EDIT FOR BATCH

    DEAR GURU I HAVE CONFIGURED SHELF LIFE FOR OUR PLANTS. WHEN A PLANT USER CREATING RESERVATION FOR SHELF LIFE ITEM , SYSTEM IS ASKING FOR BATCH NUMBER & THEY ARE SELECTING ANY  BATCH FROM F4 LIST. AFTER THAT WHEN STORE USER IS CREATING ISSUE SLIP  AGA