Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Translate DATE to time_t in Pro*C?

Re: Translate DATE to time_t in Pro*C?

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Mon, 13 Apr 1998 01:27:26 GMT
Message-ID: <353169a5.11332355@192.86.155.100>


A copy of this was sent to Henry Li <hli_at_iname.com> (if that email address didn't require changing) On Sun, 12 Apr 1998 12:03:05 -0600, you wrote:

>Hi All,
>
>Is there any way that I can translate the DATE stamp in Oracle directly
>into a time_t data type in a Pro*C program?
>
>Thanks.
>
>Haihao

If you know your timezone, yes, its straightforward:

static void process()
{
EXEC SQL BEGIN DECLARE SECTION;
    int t;
EXEC SQL END DECLARE SECTION;     EXEC SQL SELECT (new_time(sysdate,'EDT','GMT') -

                     to_date('01-jan-1970','dd-mon-yyyy')) * (24*60*60)
               INTO :t
               FROM DUAL;

    printf( "C Time = %d\n", time(NULL) );     printf( "SQL Time = %d\n", t );
}

C Time = 892430675
SQL Time = 892430675

You just convert SYSDATE into GMT, subtrace January 1'st 1970 from it and multiply by the number of seconds in a day...  

Thomas Kyte
tkyte_at_us.oracle.com
Oracle Government
Herndon VA  

http://govt.us.oracle.com/ -- downloadable utilities  



Opinions are mine and do not necessarily reflect those of Oracle Corporation  

Anti-Anti Spam Msg: if you want an answer emailed to you, you have to make it easy to get email to you. Any bounced email will be treated the same way i treat SPAM-- I delete it. Received on Sun Apr 12 1998 - 20:27:26 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US