Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DATE in embedded SQL

Status
Not open for further replies.

JTOracle

Programmer
Apr 19, 2002
4
US
I am generating a C program for specific queries and am having trouble with the DATE type. When I create a struct for a Table how do I declare this datatype?
example:

struct {
VARCHAR staffNo[ID_LEN];
VARCHAR fName[UNAME_LEN];
VARCHAR lName[UNAME_LEN];
char sex;
DATE dob; /*this doesnt work*/
.
.
.
} staffrec;

While trying to figure it out I found a variable type called OCIDATE, but "OCIDATE dob" doesnt compile either.

Any help is appreciated

John
 
What we have always done is use a VARCHAR2 to hold the date/time in whatever format we wanted and then use the TO_DATE conversion function in SQL statements to select or insert or update to a DATE column in a table. I don't think there is a date data type you can use in embedded SQL (although I could be wrong).

The examples in the Oracle PRO*C manual that have dates all show using CHAR or VARCHAR2 to hold dates.

 
I see where I can convert from a CHAR to a DATE and vice-versa...Is there a way to convert a DATE to an int?
 
If you are talking about something like a julian date, you can use:

select to_number (to_char (sysdate, 'J')) from dual;

Which returns the number of days since January 1, 4712 BC.

If you want to roll time into this (like number of seconds since some date) you will have to do some arithmetic, but it would be relatively easy.
 
I am assuming that u want to seperate the year, month and day from the date string.

In that case u can use the atoi function of c.
For ex.

char * dob; /* date of birth */
int year = atoi(dob+6);

If this is not what u r after... can u pls. b more descriptive.

cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top