PMS Information Systems
Welcome to PMS Information Systems - IBM i (AS/400) Forum !!!

Get Answers for all your queries on IBM i (AS/400).

DATE CONVERSION TIPS

View previous topic View next topic Go down

DATE CONVERSION TIPS

Post  maran on Sat Apr 24, 2010 8:20 pm

Date Conversion

Convert a Character field to a date

With no separators

Date = %date('122507' : *MDY0);

Date = %date(yymmdd_c6 : *YMD0);

Date = %date('20071225': *ISO0);

With separators

Date = %date('12/25/07' : *MDY);

Date = %date(yymmdd_c8 : *YMD);

Date = %date('2007-12-25': *ISO);

Convert a Numeric field to a Date

Date = %date(122507 : *MDY);

Date = %date(ddmmyy_n6: *DMY);

Date = %date(20071225 : *ISO);

Convert a date field to an Alpha field With no separators

mmddccyy_c8 = %char(date: *usa0);

yymmdd_c6 = %char(date: *ymd0);

cyymmdd_c7 = %char(date: *cymd0);

With Separators

mmddccyy_c10 = %char(date: *usa/);

yymmdd_c8 = %char(date: *Iso-);

cyymmdd_c9 = %char(date: *cymd/);

Convert a date field to a Numeric field

yyddd_n5 = %dec( date: *jul);

ddmmccyy_n8 = %dec( date: *eur);

Misc: Conversions

// Date/time to character With no Separators

Ccyymmdd_c8 = %char(%date :*iso0);

hhmmss_c6 = %char(%Time :*iso0);

YYMMDD = %Char(Friday : *YMD);

With Separators

Ccyymmdd_c10 = %char(%date :*iso-);

hhmmss_c8 = %char(%Time :*iso-);

YYMMDD = %Char(Friday : *YMD/);

// date to numeric...

Yymmdd_n6 = %dec(@dateA:*ymd);

Cyymmdd_n7 = %dec(@dateA:*cymd);

Ccyymmdd_n8 = %dec(@dateA:*iso);

Mmddyy_n6 = %dec(@dateA:*mdy);

Mmddyyyy_n8 = %dec(@dateA:*usa);

// Today’s date/time to numeric

Hhmmss_n6 = %Dec(%Time():*ISO);

Ccyymmdd_n8 = %Dec(%Date():*ISO);

// Today’s timestamp to numeric

Numeric20 = %Dec(%Timestamp());

// Today’s timestamp to Alpha

Alpha26 = %Char(%Timestamp());



Combining The Conversion logic

An example of converting from one format to another.

Character to Numeric – Convert ‘12/25/07’ to a Numeric *YMD format

1: First convert Character field to actual date format

%Date(‘12/25/07’:*mdy/)

2: Then Convert the date to numeric

YYMMDD_n6 = %Dec(*******):*YMD0:6:0)

3: Combine

YYMMDD_n6 = %Dec(%Date(‘12/25/07’:*mdy/ ):*YMD)

// numeric to character...

Output With no Separators and Input with no separators


Yymmdd_c6 = %char(%date( yymmdd_n6 : *ymd) :*ymd0);

Mmddyy_c6 = %char(%date( yymmdd_n6 : *ymd) :*mdy0);

Yymmdd_c6 = %char(%date( Cyymmdd_n7 : *cymd) :*ymd0);

OutPut With Separators and Input with no separators


Yymmdd_c8 = %char(%date( yymmdd_n6 : *ymd) :*ymd/);

Mmddyy_c8 = %char(%date( yymmdd_n6 : *ymd) :*mdy/);

Yymmdd_c8 = %char(%date( Cyymmdd_n7 : *cymd) :*ymd/);

Yymmdd_c8 = %char(%date( Cyymmdd_n7 : *cymd/):*ymd/);

// numeric to numeric

Cyymmdd_n7 = %dec(%date( yymmdd_n6 :*ymd):*cymd);

Ccyymmdd_n8 = %dec(%date( yymmdd_n6 :*ymd):*iso);

// character to numeric Input with Separators

Yymmdd_n6 = %dec(%date( yymmdd_c8 :*ymd/):*ymd);

cyymmdd_n7 = %dec(%date( yymmdd_c9 :*ymd/):*cymd);

Yymmdd_n6 = %dec(%date( yymmdd_c8 :*ymd/):*iso);

Input with No Separators

Yymmdd_n6 = %dec(%date( yymmdd_c6 :*ymd0):*ymd);

cyymmdd_n7 = %dec(%date( yymmdd_c6 :*ymd0):*cymd);

Yymmdd_n6 = %dec(%date( yymmdd_c6 :*ymd0):*iso);
avatar
maran
Admin

Posts : 442
Join date : 2009-07-24

View user profile http://pmsinformationsystem.forumotion.net

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum