DSN8DUAD

Returns the current date in one these 34 formats.

 /********************************************************************* 00010000
 * Module name = DSN8DUAD (DB2 sample program)                        * 00020000
 *                                                                    * 00030000
 * DESCRIPTIVE NAME = Current date reformatter (UDF)                  * 00040000
 *                                                                    * 00050000
 *                                                                    * 00060000
 *     LICENSED MATERIALS - PROPERTY OF IBM                           * 00070000
 *     5625-DB2                                                       * 00080000
 *     (C) COPYRIGHT 1998, 2003 IBM CORP.  ALL RIGHTS RESERVED.       * 00090000
 *                                                                    * 00100000
 *     STATUS = VERSION 8                                             * 00110000
 *                                                                    * 00120000
 *                                                                    * 00130000
 * Function: Returns the current date in one these 34 formats:        * 00140000
 *                                                                    * 00150000
 *             D MONTH YY  D MONTH YYYY  DD MONTH YY  DD MONTH YYYY   * 00160000
 *                 D.M.YY  D.M.YYYY      DD.MM.YY     DD.MM.YYYY      * 00170000
 *                 D-M-YY  D-M-YYYY      DD-MM-YY     DD-MM-YYYY      * 00180000
 *                 D/M/YY  D/M/YYYY      DD/MM/YY     DD/MM/YYYY      * 00190000
 *                 M/D/YY  M/D/YYYY      MM/DD/YY     MM/DD/YYYY      * 00200000
 *                 YY/M/D  YYYY/M/D      YY/MM/DD     YYYY/MM/DD      * 00210000
 *                 YY.M.D  YYYY.M.D      YY.MM.DD     YYYY.MM.DD      * 00220000
 *                         YYYY-M-D                   YYYY-MM-DD      * 00230000
 *                         YYYY-D-XX                  YYYY-DD-XX      * 00240000
 *                         YYYY-XX-D                  YYYY-XX-DD      * 00250000
 *                                                                    * 00260000
 *           where:                                                   * 00270000
 *                                                                    * 00280000
 *             D: Suppress leading zero if the day is less than 10    * 00290000
 *            DD: Retain leading zero if the day is less than 10      * 00300000
 *             M: Suppress leading zero if the month is less than 10  * 00310000
 *            MM: Retain leading zero if the month is less than 10    * 00320000
 *         MONTH: Use English-language name of month                  * 00330000
 *            XX: Use a capital Roman numeral for month               * 00340000
 *            XX: Use a capital Roman numeral for month               * 00350000
 *            YY: Use non-century year format                         * 00360000
 *          YYYY: Use century year format                             * 00370000
 *                                                                    * 00380000
 *           Example invocation:                                      * 00390000
 *            EXEC SQL SET :today = ALTDATE( "DD MONTH YY" );         * 00400000
 *                                                                    * 00410000
 * Notes:                                                             * 00420000
 *   Dependencies: Requires IBM C/C++ for OS/390 V1R3 or higher       * 00430000
 *                                                                    * 00440000
 *   Restrictions:                                                    * 00450000
 *                                                                    * 00460000
 * Module type: C program                                             * 00470000
 *   Processor: IBM C/C++ for OS/390 V1R3 or higher                   * 00480000
 * Module size: See linkedit output                                   * 00490000
 *  Attributes: Re-entrant and re-usable                              * 00500000
 *                                                                    * 00510000
 * Entry Point: DSN8DUAD                                              * 00520000
 *     Purpose: See Function                                          * 00530000
 *     Linkage: DB2SQL                                                * 00540000
 *              Invoked via SQL UDF call                              * 00550000
 *                                                                    * 00560000
 *       Input: Parameters explicitly passed to this function:        * 00570000
 *              - *format      : pointer to a char[14], null-termi-   * 00580000
 *                               nated string having the desired      * 00590000
 *                               format for the current date (see     * 00600000
 *                               "Function", above, for valid formats)* 00610000
 *              - *niFormat    : pointer to a short integer having    * 00620000
 *                               the null indicator variable for      * 00630000
 *                               *format.                             * 00640000
 *              - *fnName      : pointer to a char[138], null-termi-  * 00650000
 *                               nated string having the UDF family   * 00660000
 *                               name of this function.               * 00670000
 *              - *specificName: pointer to a char[129], null-termi-  * 00680000
 *                               nated string having the UDF specific * 00690000
 *                               name of this function.               * 00700000
 *                                                                    * 00710000
 *                                                                    * 00720000
 *      Output: Parameters explicitly passed by this function:        * 00730000
 *              - *dateOut     : pointer to a char[18], null-termi-   * 00740000
 *                               nated string to receive the current  * 00750000
 *                               date in the formatted indicated by   * 00760000
 *                               *format.                             * 00770000
 *              - *niDateOut   : pointer to a short integer to re-    * 00780000
 *                               ceive the null indicator variable    * 00790000
 *                               for *dateOut.                        * 00800000
 *              - *sqlstate    : pointer to a char[06], null-termi-   * 00810000
 *                               nated string to receive the SQLSTATE.* 00820000
 *              - *message     : pointer to a char[70], null-termi-   * 00830000
 *                               nated string to receive a diagnostic * 00840000
 *                               message if one is generated by this  * 00850000
 *                               function.                            * 00860000
 *                                                                    * 00870000
 * Normal Exit: Return Code: SQLSTATE = 00000                         * 00880000
 *              - Message: none                                       * 00890000
 *                                                                    * 00900000
 *  Error Exit: Return Code: SQLSTATE = 38601                         * 00910000
 *              - Message: DSN8DUAD Error: No output format entered   * 00920000
 *              - Message: DSN8DUAD Error: Unknown format specified   * 00930000
 *                                                                    * 00940000
 *    External References:                                            * 00950000
 *             - Routines/Services: None                              * 00960000
 *             - Data areas       : None                              * 00970000
 *             - Control blocks   : None                              * 00980000
 *                                                                    * 00990000
 *                                                                    * 01000000
 *  Pseudocode:                                                       * 01010000
 *   DSN8DUAD:                                                        * 01020000
 *   - Verify that a valid format for the current date was received:  * 01030000
 *     - if *format is blank or niFormat is not 0, no format passed:  * 01040000
 *       - issue SQLSTATE 38601 and a diagnostic message              * 01050000
 *   - Verify that a valid format for the current date was received:  * 01060000
 *   - Call formatDate to convert the current date in the indicated   * 01070000
 *     format.                                                        * 01080000
 *   - If no errors, unset null indicators, and return SQLSTATE 00000 * 01090000
 *     else set null indicator and return null date out.              * 01100000
 *   End DSN8DUAD                                                     * 01110000
 *                                                                    * 01120000
 *   formatDate:                                                      * 01130000
 *   - Use the date format to generate a specification string for     * 01140000
 *     the getDate function                                           * 01150000
 *   - Call getDate                                                   * 01160000
 *   - Perform edits on the result as appropriate:                    * 01170000
 *     - call Remove0 to strip leading zeroes from the day and/or     * 01180000
 *       month                                                        * 01190000
 *     - call romanMonth to convert the month to a roman numeral      * 01200000
 *   - If *format is not one of the 34 supported formats:             * 01210000
 *     - issue SQLSTATE 38601 and a diagnostic message                * 01220000
 *   End formatDate                                                   * 01230000
 *                                                                    * 01240000
 *   getDate:                                                         * 01250000
 *   - invoke the time() library function to query calendar time.     * 01260000
 *   - invoke the localtime() library function to convert and correct * 01270000
 *     for local time                                                 * 01280000
 *   - invoke the strftime() library function to format the date from * 01290000
 *     from the time vector according to specification generated by   * 01300000
 *     the local formatDate() function.                               * 01310000
 *   End getDate                                                      * 01320000
 *                                                                    * 01330000
 *   Remove0:                                                         * 01340000
 *   - check the passed string for a character zero in the passed     * 01350000
 *     location.                                                      * 01360000
 *   - if a zero is found, eliminate it by shifting all bytes to its  * 01370000
 *     right 1 byte leftward.                                         * 01380000
 *   End Remove0                                                      * 01390000
 *                                                                    * 01400000
 *   romanMonth                                                       * 01410000
 *   - convert the month (01-12) to a roman numeral (I-XII).          * 01420000
 *   End romanMonth                                                   * 01430000
 *                                                                    * 01440000
 * Change Log:                                                        * 01450000
 * 2002/10/17 PQ66488 Fix date truncation error                    @01* 01460000
 *                                                                    * 01470000
 *                                                                    * 01480000
 *********************************************************************/ 01490000
                                                                        01500000
 #pragma linkage(DSN8DUAD,fetchable)                                    01510000
                                                                        01520000
 /********************** C library definitions ***********************/ 01530000
 #include <stdio.h>                                                     01540000
 #include <string.h>                                                    01550000
 #include <time.h>                                                      01560000
                                                                        01570000
 /***************************** Equates ******************************/ 01580000
 #define     NULLCHAR     '\0'         /* Null character             */ 01590000
                                                                        01600000
 #define     MATCH          0          /* Comparison status: Equal   */ 01610000
 #define     NOT_OK         0          /* Run status indicator: Error*/ 01620000
 #define     OK             1          /* Run status indicator: Good */ 01630000
                                                                        01640000
                                                                        01650000
 /*********************** DSN8DUAD functions *************************/ 01660000
 void DSN8DUAD                         /* main routine               */ 01670000
 ( char        *format,                /* in: format for dateOut     */ 01680000
   char        *dateOut,               /* out: formatted current date*/ 01690000
   short int   *niFormat,              /* in: indic var, format      */ 01700000
   short int   *niDateOut,             /* out: indic var for dateOut */ 01710000
   char        *sqlstate,              /* out: SQLSTATE              */ 01720000
   char        *fnName,                /* in: family name of function*/ 01730000
   char        *specificName,          /* in: specific name of func  */ 01740000
   char        *message                /* out: diagnostic message    */ 01750000
 );                                                                     01760000
                                                                        01770000
 int formatDate                        /* format the current date    */ 01780000
 ( char        *dateOut,               /* out: formatted curr date   */ 01790000
   char        *message,               /* out: diagnostic message    */ 01800000
   char        *sqlstate,              /* out: SQLSTATE              */ 01810000
   char        *format                 /* in: desired format         */ 01820000
 );                                                                     01830000
                                                                        01840000
 void getDate                          /* gets curr date, formatted  */ 01850000
 ( char        *dateOut,               /* out: formatted current date*/ 01860000
   char        *dateFmt                /* in: desired date format    */ 01870000
 );                                                                     01880000
                                                                        01890000
 void Remove0                          /* remove 0 from indic. byte  */ 01900000
 ( char        *string,                /* in/out: character string   */ 01910000
   short int   loc                     /* in: loc'n of zero to remove*/ 01920000
 );                                                                     01930000
                                                                        01940000
 char *romanMonth();                   /* get roman# of curr month#  */ 01950000
                                                                        01960000
                                                                        01970000
 /********************************************************************/ 01980000
 /*************************** main routine ***************************/ 01990000
 /********************************************************************/ 02000000
 void DSN8DUAD                         /* main routine               */ 02010000
 ( char        *format,                /* in: format for dateOut     */ 02020000
   char        *dateOut,               /* out: formatted current date*/ 02030000
   short int   *niFormat,              /* in: indic var, format      */ 02040000
   short int   *niDateOut,             /* out: indic var for dateOut */ 02050000
   char        *sqlstate,              /* out: SQLSTATE              */ 02060000
   char        *fnName,                /* in: family name of function*/ 02070000
   char        *specificName,          /* in: specific name of func  */ 02080000
   char        *message                /* out: diagnostic message    */ 02090000
 )                                                                      02100000
 /********************************************************************* 02110000
 *                                                                    * 02120000
 * Assumptions:                                                       * 02130000
 * - *format        points to a char[14], null-terminated string      * 02140000
 * - *dateOut       points to a char[18], null-terminated string      * 02150000
 * - *niFormat      points to a short integer                         * 02160000
 * - *niDateOut     points to a short integer                         * 02170000
 * - *sqlstate      points to a char[06], null-terminated string      * 02180000
 * - *fnName        points to a char[138], null-terminated string     * 02190000
 * - *specificName  points to a char[129], null-terminated string     * 02200000
 * - *message       points to a char[70], null-terminated string      * 02210000
 *********************************************************************/ 02220000
 {                                                                      02230000
                                                                        02240000
   /************************ local variables *************************/ 02250000
   short int   status = OK;            /* DSN8DUAD run status        */ 02260000
                                                                        02270000
                                                                        02280000
   /******************************************************************* 02290000
   * Verify that a format has been passed in                          * 02300000
   *******************************************************************/ 02310000
   if( *niFormat || ( strlen( format ) == 0 ) )                         02320000
     {                                                                  02330000
       status = NOT_OK;                                                 02340000
       strcpy( message,                                                 02350000
               "DSN8DUAD Error: No output format entered" );            02360000
       strcpy( sqlstate, "38601" );                                     02370000
     }                                                                  02380000
                                                                        02390000
   /******************************************************************* 02400000
   * Call formatDate to format the current date according to format   * 02410000
   *******************************************************************/ 02420000
   if( status == OK )                                                   02430000
     status = formatDate( dateOut, message, sqlstate, format );         02440000
                                                                        02450000
                                                                        02460000
   /******************************************************************* 02470000
   * If formatting was successful, clear the message buffer and sql-  * 02480000
   * state, and unset the SQL null indicator for dateOut.             * 02490000
   *******************************************************************/ 02500000
   if( status == OK )                                                   02510000
     {                                                                  02520000
       *niDateOut = 0;                                                  02530000
       message[0] = NULLCHAR;                                           02540000
       strcpy( sqlstate,"00000" );                                      02550000
     }                                                                  02560000
   /******************************************************************* 02570000
   * If errors occurred, clear the dateOut buffer and set the SQL null* 02580000
   * indicator.  A diagnostic message and the SQLSTATE have been set  * 02590000
   * where the error was detected.                                    * 02600000
   *******************************************************************/ 02610000
   else                                                                 02620000
     {                                                                  02630000
       dateOut[0] = NULLCHAR;                                           02640000
       *niDateOut = -1;                                                 02650000
     }                                                                  02660000
                                                                        02670000
   return;                                                              02680000
                                                                        02690000
 } /* end of DSN8DUAD */                                                02700000
                                                                        02710000
                                                                        02720000
 /********************************************************************/ 02730000
 /***************************** functions ****************************/ 02740000
 /********************************************************************/ 02750000
 int formatDate                        /* format the current date    */ 02760000
 ( char        *dateOut,               /* out: formatted curr date   */ 02770000
   char        *message,               /* out: diagnostic message    */ 02780000
   char        *sqlstate,              /* out: SQLSTATE              */ 02790000
   char        *format                 /* in: desired format         */ 02800000
 )                                                                      02810000
 /********************************************************************* 02820000
 * Places the current date formatted according to format in dateOut.  * 02830000
 * If processing is successful, formatDaete returns OK.  Otherwise, a * 02840000
 * diagnostic message is placed in message, the SQLSTATE is 38601,    * 02850000
 * and formatDate returns NOT_OK.                                     * 02860000
 *********************************************************************/ 02870000
 {                                                                      02880000
   short int   func_status = OK;       /* function status indicator  */ 02890000
   char        dateFmt[14];            /* date format work buffer    */ 02900000
                                                                        02910000
   /******************************************************************* 02920000
   * get the current date and format it according to format           * 02930000
   *******************************************************************/ 02940000
   if( strcmp( format,"D MONTH YY" ) == MATCH )                         02950000
     {                                                                  02960000
       getDate( dateOut,"%d %B %y" );  /* format date as DD MONTH YY */ 02970000
       Remove0( dateOut,0 );           /* strip leading 0 if day < 10*/ 02980000
     }                                                                  02990000
   else if( strcmp( format,"D MONTH YYYY" ) == MATCH )                  03000000
     {                                                                  03010000
       getDate( dateOut,"%d %B %Y" );  /* formt date as DD MONTH YYYY*/ 03020000
       Remove0( dateOut,0 );           /* strip leading 0 if day < 10*/ 03030000
     }                                                                  03040000
   else if( strcmp( format,"DD MONTH YY" ) == MATCH )                   03050000
     {                                                                  03060000
       getDate( dateOut,"%d %B %y" );  /* format date as DD MONTH YY */ 03070000
     }                                                                  03080000
   else if( strcmp( format,"DD MONTH YYYY" ) == MATCH )                 03090000
     {                                                                  03100000
       getDate( dateOut,"%d %B %Y" );  /* formt date as DD MONTH YYYY*/ 03110000
     }                                                                  03120000
   else if( strcmp( format,"D.M.YY" ) == MATCH )                        03130000
     {                                                                  03140000
       getDate( dateOut,"%d.%m.%y" );  /* format date as DD.MM.YY     */03150000
       Remove0( dateOut,3 );           /* strip leading 0 if month<10*/ 03160000
       Remove0( dateOut,0 );           /* strip leading 0 if day < 10*/ 03170000
     }                                                                  03180000
   else if( strcmp( format,"D.M.YYYY" ) == MATCH )                      03190000
     {                                                                  03200000
       getDate( dateOut,"%d.%m.%Y" );  /* format date as DD.MM.YYYY   */03210000
       Remove0( dateOut,3 );           /* strip leading 0 if month<10*/ 03220000
       Remove0( dateOut,0 );           /* strip leading 0 if day < 10*/ 03230000
     }                                                                  03240000
   else if( strcmp( format,"DD.MM.YY" ) == MATCH )                      03250000
     {                                                                  03260000
       getDate( dateOut,"%d.%m.%y" );  /* format date as DD.MM.YY     */03270000
     }                                                                  03280000
   else if( strcmp( format,"DD.MM.YYYY" ) == MATCH )                    03290000
     {                                                                  03300000
       getDate( dateOut,"%d.%m.%Y" );  /* format date as DD.MM.YYYY   */03310000
     }                                                                  03320000
   else if( strcmp( format,"D-M-YY" ) == MATCH )                        03330000
     {                                                                  03340000
       getDate( dateOut,"%d-%m-%y" );  /* format date as DD-MM-YY     */03350000
       Remove0( dateOut,3 );           /* strip leading 0 if month<10*/ 03360000
       Remove0( dateOut,0 );           /* strip leading 0 if day < 10*/ 03370000
     }                                                                  03380000
   else if( strcmp( format,"D-M-YYYY" ) == MATCH )                      03390000
     {                                                                  03400000
       getDate( dateOut,"%d-%m-%Y" );  /* format date as DD-MM-YYYY   */03410000
       Remove0( dateOut,3 );           /* strip leading 0 if month<10*/ 03420000
       Remove0( dateOut,0 );           /* strip leading 0 if day < 10*/ 03430000
     }                                                                  03440000
   else if( strcmp( format,"DD-MM-YY" ) == MATCH )                      03450000
     {                                                                  03460000
       getDate( dateOut,"%d-%m-%y" );  /* format date as DD-MM-YY     */03470000
     }                                                                  03480000
   else if( strcmp( format,"DD-MM-YYYY" ) == MATCH )                    03490000
     {                                                                  03500000
       getDate( dateOut,"%d-%m-%Y" );  /* format date as DD-MM-YYYY   */03510000
     }                                                                  03520000
   else if( strcmp( format,"D/M/YY" ) == MATCH )                        03530000
     {                                                                  03540000
       getDate( dateOut,"%d/%m/%y" );  /* format date as DD/MM/YY     */03550000
       Remove0( dateOut,3 );           /* strip leading 0 if month<10*/ 03560000
       Remove0( dateOut,0 );           /* strip leading 0 if day < 10*/ 03570000
     }                                                                  03580000
   else if( strcmp( format,"D/M/YYYY" ) == MATCH )                      03590000
     {                                                                  03600000
       getDate( dateOut,"%d/%m/%Y" );  /* format date as DD/MM/YYYY   */03610000
       Remove0( dateOut,3 );           /* strip leading 0 if month<10*/ 03620000
       Remove0( dateOut,0 );           /* strip leading 0 if day < 10*/ 03630000
     }                                                                  03640000
   else if( strcmp( format,"DD/MM/YY" ) == MATCH )                      03650000
     {                                                                  03660000
       getDate( dateOut,"%d/%m/%y" );  /* format date as DD/MM/YY     */03670000
     }                                                                  03680000
   else if( strcmp( format,"DD/MM/YYYY" ) == MATCH )                    03690000
     {                                                                  03700000
       getDate( dateOut,"%d/%m/%Y" );  /* format date as DD/MM/YYYY   */03710000
     }                                                                  03720000
   else if( strcmp( format,"M/D/YY" ) == MATCH )                        03730000
     {                                                                  03740000
       getDate( dateOut,"%m/%d/%y" );  /* format date as MM/DD/YY     */03750000
       Remove0( dateOut,3 );           /* strip leading 0 if day < 10*/ 03760000
       Remove0( dateOut,0 );           /* strip leading 0 if month<10*/ 03770000
     }                                                                  03780000
   else if( strcmp( format,"M/D/YYYY" ) == MATCH )                      03790000
     {                                                                  03800000
       getDate( dateOut,"%m/%d/%Y" );  /* format date as MM/DD/YYYY   */03810000
       Remove0( dateOut,3 );           /* strip leading 0 if day < 10*/ 03820000
       Remove0( dateOut,0 );           /* strip leading 0 if month<10*/ 03830000
     }                                                                  03840000
   else if( strcmp( format,"MM/DD/YY" ) == MATCH )                      03850000
     {                                                                  03860000
       getDate( dateOut,"%m/%d/%y" );  /* format date as MM/DD/YY     */03870000
     }                                                                  03880000
   else if( strcmp( format,"MM/DD/YYYY" ) == MATCH )                    03890000
     {                                                                  03900000
       getDate( dateOut,"%m/%d/%Y" );  /* format date as MM/DD/YYYY   */03910000
     }                                                                  03920000
   else if( strcmp( format,"YY/M/D" ) == MATCH )                        03930000
     {                                                                  03940000
       getDate( dateOut,"%y/%m/%d" );  /* format date as YY/MM/DD     */03950000
       Remove0( dateOut,6 );           /* strip leading 0 if day < 10*/ 03960000
       Remove0( dateOut,3 );           /* strip leading 0 if month<10*/ 03970000
     }                                                                  03980000
   else if( strcmp( format,"YY/MM/DD" ) == MATCH )                      03990000
     {                                                                  04000000
       getDate( dateOut,"%y/%m/%d" );  /* format date as YY/MM/DD     */04010000
     }                                                                  04020000
   else if( strcmp( format,"YYYY/M/D" ) == MATCH )                      04030000
     {                                                                  04040000
       getDate( dateOut,"%Y/%m/%d" );  /* format date as YYYY/MM/DD   */04050000
       Remove0( dateOut,8 );           /* strip leading 0 if day < 10*/ 04060000
       Remove0( dateOut,5 );           /* strip leading 0 if month<10*/ 04070000
     }                                                                  04080000
   else if( strcmp( format,"YYYY/MM/DD" ) == MATCH )                    04090000
     {                                                                  04100000
       getDate( dateOut,"%Y/%m/%d" );  /* format date as YYYY/MM/DD   */04110000
     }                                                                  04120000
   else if( strcmp( format,"YY.M.D" ) == MATCH )                        04130000
     {                                                                  04140000
       getDate( dateOut,"%y.%m.%d" );  /* format date as YY.MM.DD     */04150000
       Remove0( dateOut,6 );           /* strip leading 0 if day < 10*/ 04160000
       Remove0( dateOut,3 );           /* strip leading 0 if month<10*/ 04170000
     }                                                                  04180000
   else if( strcmp( format,"YY.MM.DD" ) == MATCH )                      04190000
     {                                                                  04200000
       getDate( dateOut,"%y.%m.%d" );  /* format date as YY.MM.DD     */04210000
     }                                                                  04220000
   else if( strcmp( format,"YYYY.M.D" ) == MATCH )                      04230000
     {                                                                  04240000
       getDate( dateOut,"%Y.%m.%d" );  /* format date as YYYY.MM.DD   */04250000
       Remove0( dateOut,8 );           /* strip leading 0 if day < 10*/ 04260000
       Remove0( dateOut,5 );           /* strip leading 0 if month<10*/ 04270000
     }                                                                  04280000
   else if( strcmp( format,"YYYY.MM.DD" ) == MATCH )                    04290000
     {                                                                  04300000
       getDate( dateOut,"%Y.%m.%d" );  /* format date as YYYY.MM.DD   */04310000
     }                                                                  04320000
   else if( strcmp( format,"YYYY-M-D" ) == MATCH )                      04330000
     {                                                                  04340000
       getDate( dateOut,"%Y-%m-%d" );  /* format date as YYYY-MM-DD   */04350000
       Remove0( dateOut,8 );           /* strip leading 0 if day < 10*/ 04360000
       Remove0( dateOut,5 );           /* strip leading 0 if month<10*/ 04370000
     }                                                                  04380000
   else if( strcmp( format,"YYYY-MM-DD" ) == MATCH )                    04390000
     {                                                                  04400000
       getDate( dateOut,"%Y-%m-%d" );  /* format date as YYYY-MM-DD   */04410000
     }                                                                  04420000
   else if( strcmp( format,"YYYY-D-XX" ) == MATCH )                     04430000
     {                                                                  04440000
       strcpy( dateFmt, "%Y-%d-" );    /* start format as YYYY-DD-   */ 04450000
       strcat( dateFmt, romanMonth() );/* append roman# for curr mo. */ 04460000
       getDate( dateOut,dateFmt );     /* format date as YYYY-DD-XX  */ 04470000
       Remove0( dateOut,5 );           /* strip leading 0 if day < 10*/ 04480000
     }                                                                  04490000
   else if( strcmp( format,"YYYY-DD-XX" ) == MATCH )                    04500000
     {                                                                  04510000
       strcpy( dateFmt, "%Y-%d-" );    /* start format as YYYY-DD-   */ 04520000
       strcat( dateFmt, romanMonth() );/* append roman# for curr mo. */ 04530000
       getDate( dateOut,dateFmt );     /* format date as YYYY-DD-XX  */ 04540000
     }                                                                  04550000
   else if( strcmp( format,"YYYY-XX-D" ) == MATCH )                     04560000
     {                                                                  04570000
       strcpy( dateFmt, "%Y-" );       /* start format as YYYY-      */ 04580000
       strcat( dateFmt, romanMonth() );/* append roman# for curr mo. */ 04590000
       strcat( dateFmt, "-%d" );       /* append -DD to format       */ 04600000
       getDate( dateOut,dateFmt );     /* get date as YYYY-XX-DD     */ 04610000
       Remove0( dateOut,               /* strip leading 0 if day < 10*/ 04620000
                strlen(dateFmt) );                                      04630000
     }                                                                  04640000
   else if( strcmp( format,"YYYY-XX-DD" ) == MATCH )                    04650000
     {                                                                  04660000
       strcpy( dateFmt, "%Y-" );       /* start format as YYYY-      */ 04670000
       strcat( dateFmt, romanMonth() );/* append roman# for curr mo. */ 04680000
       strcat( dateFmt, "-%d" );       /* append -DD to format       */ 04690000
       getDate( dateOut,dateFmt );     /* get date as YYYY-XX-DD     */ 04700000
     }                                                                  04710000
   else                                                                 04720000
     {                                                                  04730000
       func_status = NOT_OK;                                            04740000
       strcpy( message,                                                 04750000
               "DSN8DUAD Error: Unknown format specified" );            04760000
       strcpy( sqlstate, "38601" );                                     04770000
     }                                                                  04780000
                                                                        04790000
   return( func_status );                                               04800000
 } /* end of formatDate */                                              04810000
                                                                        04820000
 /********************************************************************/ 04830000
 /***************************** functions ****************************/ 04840000
 /********************************************************************/ 04850000
 void getDate                          /* gets curr date, formatted  */ 04860000
 ( char        *dateOut,               /* out: formatted current date*/ 04870000
   char        *dateFmt                /* in: desired date format    */ 04880000
 )                                                                      04890000
 /********************************************************************* 04900000
 * Obtains the current date from the system and formats it according  * 04910000
 * to the format string in *dateFmt. The result is placed in dateOut.*  04920000
 *                                                                    * 04930000
 * This function uses the C function localtime to obtain the system   * 04940000
 * time and date and the C function strftime to format it according   * 04950000
 * to *dateFmt.  For this program, the following format tokens were   * 04960000
 * used.  See the C/C++ library reference manuals for more info.      * 04970000
 *                                                                    * 04980000
 * %B = full month name                                               * 04990000
 * %d = day of the month                                              * 05000000
 * %m = month (01-12)                                                 * 05010000
 * %y = year with century                                             * 05020000
 * %Y = year with century                                             * 05030000
 *********************************************************************/ 05040000
 {                                                                      05050000
   time_t      t;                      /* buff for system time macro */ 05060000
   struct tm   *tmPtr;                 /* ->buff for time.h tm struct*/ 05070000
   short int   i;                      /* len of str rtnd by strftime*/ 05080000
   char        dateBuff[19];           /* gets formatted date     @01*/ 05090000
                                                                        05100000
   /******************************************************************* 05110000
   * Use the C function localtime to get the current date from the    * 05120000
   * system, then use the C function strftime to format it according  * 05130000
   * to *dateFmt.                                                     * 05140000
   *******************************************************************/ 05150000
   t = time(NULL);                                                      05160000
   tmPtr = localtime(&t);                                               05170000
   i = strftime( dateBuff,                                              05180000
                 sizeof(dateBuff)-1,                                    05190000
                 dateFmt,                                               05200000
                 tmPtr );                                               05210000
                                                                        05220000
   if( i > 0 )                                                          05230000
     strcpy( dateOut,dateBuff );                                        05240000
                                                                        05250000
   return;                                                              05260000
 } /* end getDate */                                                    05270000
                                                                        05280000
                                                                        05290000
 void Remove0                                                           05300000
 ( char        *string,                /* in/out: character string   */ 05310000
   short int   loc                     /* in: loc'n of byte to remove*/ 05320000
 )                                                                      05330000
 /********************************************************************* 05340000
 * Checks *string at the location indicated by loc and, if a character* 05350000
 * zero resides there, removes it from *string by shifting all bytes  * 05360000
 * to the right of it leftward by 1 byte.                             * 05370000
 *********************************************************************/ 05380000
 {                                                                      05390000
   short int  i;                                                        05400000
                                                                        05410000
   if( string[loc] == '0' )                                             05420000
     {                                                                  05430000
       for( i=loc; i<(strlen(string)-1); i++ )                          05440000
         string[i] = string[i+1];                                       05450000
       string[i] = NULLCHAR;                                            05460000
     }                                                                  05470000
                                                                        05480000
   return;                                                              05490000
 } /* end Remove0 */                                                    05500000
                                                                        05510000
                                                                        05520000
 char *romanMonth()                                                     05530000
 /********************************************************************* 05540000
 * Returns the roman numeral that corresponds to the month number of  * 05550000
 * the current month.                                                 * 05560000
 *********************************************************************/ 05570000
 {                                                                      05580000
   char        romNum[5];              /* gets roman numeral         */ 05590000
   char        monthNo[18];            /* gets current month number  */ 05600000
                                                                        05610000
   /******************************************************************* 05620000
   * call getDate to get the month number of the current month        * 05630000
   *******************************************************************/ 05640000
   getDate( monthNo,"%m" );            /* format date as MM          */ 05650000
                                                                        05660000
   /******************************************************************* 05670000
   * look up the roman numeral that corresponds to the current month  * 05680000
   *******************************************************************/ 05690000
   if(      strcmp( monthNo,"01" ) == MATCH ) strcpy( romNum, "I" );    05700000
   else if( strcmp( monthNo,"02" ) == MATCH ) strcpy( romNum, "II" );   05710000
   else if( strcmp( monthNo,"03" ) == MATCH ) strcpy( romNum, "III" );  05720000
   else if( strcmp( monthNo,"04" ) == MATCH ) strcpy( romNum, "IV" );   05730000
   else if( strcmp( monthNo,"05" ) == MATCH ) strcpy( romNum, "V" );    05740000
   else if( strcmp( monthNo,"06" ) == MATCH ) strcpy( romNum, "VI" );   05750000
   else if( strcmp( monthNo,"07" ) == MATCH ) strcpy( romNum, "VII" );  05760000
   else if( strcmp( monthNo,"08" ) == MATCH ) strcpy( romNum, "VIII" ); 05770000
   else if( strcmp( monthNo,"09" ) == MATCH ) strcpy( romNum, "IX" );   05780000
   else if( strcmp( monthNo,"10" ) == MATCH ) strcpy( romNum, "X" );    05790000
   else if( strcmp( monthNo,"11" ) == MATCH ) strcpy( romNum, "XI" );   05800000
   else strcpy( romNum, "XII" );                                        05810000
                                                                        05820000
   /******************************************************************* 05830000
   * return the result                                                * 05840000
   *******************************************************************/ 05850000
   return( romNum );                                                    05860000
                                                                        05870000
 } /* end romanMonth */                                                 05880000