dbdatecrack

DB Library for C

DB Library for C

dbdatecrack

Converts a computer-readable DBDATETIME value into user-accessible format.

Syntax

RETCODE dbdatecrack (
PDBPROCESS
dbproc,
LPDBDATEREC
dateinfo,
LPCDBDATETIME
datetime );

Arguments

dbproc

Is the DBPROCESS structure that is the handle for a particular workstation or Microsoft® SQL Server™ 2000 process. It contains all the information that DB-Library uses to manage communications and data between the workstation and SQL Server.

dateinfo

Is a pointer to the DBDATEREC structure to contain the parts of datetime. DBDATEREC is defined as follows:

typedef struct dbdaterec
{
    int year;            // 1753 - 9999 
    int quarter;         // 1 - 4 
    int month;           // 1 - 12 
    int dayofyear;       // 1 - 366 
    int day;             // 1 - 31 
    int week;            // 1 - 54 (for leap years) 
    int weekday;         // 1 - 7 (Mon. - Sun.) 
    int hour;            // 0 - 23 
    int minute;          // 0 - 59 
    int second;          // 0 - 59 
    int millisecond;     // 0 - 999 
} DBDATEREC;

datetime

Is a pointer to the DBDATETIME value of interest.

Returns

SUCCEED or FAIL.

Remarks

dbdatecrack converts a DBDATETIME value into its integer components and puts them into a DBDATEREC structure.

DBDATETIME structures store date and time values in an internal format. For example, a time value is stored as the number of 300ths of a second since midnight, and a date value is stored as the number of days since January 1, 1900. The dbdatecrack function converts the internal value to something easily usable by an application.

Using dbdatecrack function accepts a NULL value for the dbproc parameter. In SQL Server version 6.0 or earlier, the dbdatecrack function can only be called if a DBPROCESS structure is active.

Examples

The following code fragment shows how to use dbdatecrack:

dbcmd(dbproc, "SELECT name, crdate FROM master..sysdatabases");
dbsqlexec(dbproc);
dbresults(dbproc);

while (dbnextrow(dbproc) != NO_MORE_ROWS)
{
   // Print the database name and its date info 
   dbconvert(dbproc,
      dbcoltype(dbproc, 2), dbdata(dbproc, 2),
      dbdatlen(dbproc, 2), SQLCHAR, datestring, -1);
   printf("%s: %s\n", (char *) (dbdata(dbproc, 1)), datestring);

   // Break up the creation date into its constituent parts 
   dbdatecrack(dbproc, &dateinfo, (DBDATETIME *) (dbdata(dbproc, 2)));

   // Print the parts of the creation date 
   printf("\tYear = %d.\n", dateinfo.year);
   printf("\tMonth = %d.\n", dateinfo.month);
   printf("\tDay of month = %d.\n", dateinfo.day);
   printf("\tDay of year = %d.\n", dateinfo.dayofyear);
   printf("\tDay of week = %d.\n", dateinfo.weekday);
   printf("\tHour = %d.\n", dateinfo.hour);
   printf("\tMinute = %d.\n", dateinfo.minute);
   printf("\tSecond = %d.\n", dateinfo.second);
   printf("\tMillisecond = %d.\n", dateinfo.millisecond);
}

See Also

dbconvert

dbdata