IBM Support

ILEC Example Using QWCCVTDT to Change the Time Zone of a Date

Troubleshooting


Problem

This document contains a ILEC example using QWCCVTDT to change the time zone of a date.

Resolving The Problem

This document contains a C example using QWCCVTDT to change the time zone of a date.

If a user wants to change the current time on their system to the time in another time zone for use in an application, the user can use the QWCCVTDT API. An example of converting from the current system time to Mountain Standard Time follows:
 
Disclaimer: IBM accepts no responsibility for its correctness.

Example ILEC source WCCCVDT.C
#include "qwccvtdt.h" /* Convert date api.                       */
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>

typedef _Packed struct ErrStruct {
  int BytesProvided;
  int BytesAvailable;
  char MsgId[7];
  char reserved;
  char ExceptionData[255];
} ErrStruct_t;

static void InitErrStruct(ErrStruct_t *);

static void InitErrStruct(ErrStruct_t *pesErrCode)
{
   memset(pesErrCode, '\0', 16);
   pesErrCode->BytesProvided = sizeof(ErrStruct_t);
   pesErrCode->BytesAvailable = 0;
   return;
} /* end InitErrStruct() */


void main()
{
char InputFormat[10];
char OutputFormat[10];
char InputDate[20];
char OutputDate[20];
char InTimezone[10];
char OutTimezone[10];
char TimezoneInfo[111];
int  lengthTimezone = 111;
char precision[1];
ErrStruct_t ErrorStructure;
ErrStruct_t ErrorCode;

memset(InputFormat,0x00,sizeof(InputDate));
memset(OutputFormat,0x00,sizeof(OutputDate));

  memcpy(InputFormat,"*CURRENT  ",sizeof(InputFormat));
  memcpy(OutputFormat,"*YYMD      ",10);
  memcpy(OutTimezone,"QN0700MST ",10);
  memcpy(precision,"1",1);

InitErrStruct(&ErrorCode);

QWCCVTDT((void *) &InputFormat,
     (void *) &InputDate,
     (void *) &OutputFormat,
     (void *) &OutputDate,
     (void *) &ErrorCode,
     (void *) &InTimezone,
     (void *) &OutTimezone,
     (void *) &TimezoneInfo,
     (void *) &lengthTimezone,
     (void *) &precision);

if (ErrorCode.BytesAvailable > 0)
{
   printf("Message Id: %7.7s\n",ErrorCode.MsgId);
   exit(1);
}
printf("The new timezone is %s \n", OutTimezone);
printf("The current time is %s \n", OutputDate);
} 
Compile the program using 
CRTBNDC PGM(<your lib>/WCCVTDT) SRCFILE(<yourlib>/QCSRC) (WCCVTDT)
Call from command:
CALL WCCVTDT
 
The output will be presented on the ILE stdout panel:

The new timezone is QN0700MST            
The current time is 20250414145514104739
Press ENTER to end terminal session.
   

image-20250414155447-3
 
The current time is using timestamp format (YYYYMMDDHHMMSSUUUUUU) 
Running the same API a few second later for Central Daylight Time (CDT), i.e.,
memcpy(OutTimezone,"QN0600CST ",10); 
The new timezone is QN0600CST           
The current time is 20250414155516776972
Press ENTER to end terminal session.    
image-20250414155540-4

20250414155516776972 maps as 2025-04-14-15.55.16.776972

Link for list of time zones
List of time zones
Link for QWCCVTDT API doc
QWCCVTDT API

[{"Type":"MASTER","Line of Business":{"code":"LOB68","label":"Power HW"},"Business Unit":{"code":"BU070","label":"IBM Infrastructure"},"Product":{"code":"SWG60","label":"IBM i"},"ARM Category":[{"code":"a8m3p000000hB4rAAE","label":"API"},{"code":"a8m0z0000000CHtAAM","label":"Programming ILE Languages"}],"ARM Case Number":"","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"All Versions"}]

Historical Number

617064034

Document Information

Modified date:
14 April 2025

UID

nas8N1011273