USING %TIME BUILT-IN FUNCTION
Get Current
Time:
MyTime = %DEC(%TIME())
Where MyTime =
Time in HHMMSS - 6,0
Get Current Time
in USA Format:
MyTime =
%Char(%Time():*USA)
Where MyTime =
Time in USA Format – 8A (Format - '01:01 AM')
Get Current Time
Stamp:
MyTimeStamp = %DEC(%TIMESTAMP())
Where MyTimeStamp
= 20,0
TO CONVERT A
TIME TO A SPECIFIED FORMAT WITH ‘.’ AS SEPERATOR:
OUT_TIME = %TIME(INP_TIME:*USA)
Where OUT_TIME
= 8 Character
DATE CONVERSIONS
USING %DATE() BUILT-IN FUNCTION
UDATE:
UDATE = MMDDYY 6,0
UMONTH = MM 2,0
UYEAR = YY 2,0
UDAY = DD 2,0
*DATE:
*DATE = MMDDYYYY 8,0
*MONTH = YY 2,0
*YEAR = YYYY 4,0
*DAY = YY 2,0
Length of Date
Variables in Various Formats:
For
*MDY, *DMY, *YMD – 6 digits
For *CYMD – 7 digits
For *USA and *ISO – 8 digits
For *CYMD – 7 digits
For *USA and *ISO – 8 digits
TO GET CURRENT
DATE:
To
Get Current Date in YYYYMMDD
MyDate = %DEC(%DATE())
Where MyDate =
YYYYMMDD - 8,0
To
Get Current Date in CYYMMDD
MyDate = %DEC(%DATE():*CYMD)
Where MyDate =
CCYYMMDD - 8,0
To
Get Current Date in YYMMDD
MyDate = %DEC(%DATE():*YMD)
Where MyDate =
YYMMDD - 6,0
To
Get Current Date in MMDDYY
MyDate = %DEC(%DATE():*MDY)
Where MyDate =
MMDDYY - 6,0
TO CONVERT A DATE TO A SPECIFIED FORMAT WITH ‘/’ AS
SEPERATOR:
OUT_DATE = %CHAR(%DATE(INP_DATE):*USA/)
Where OUT_DATE
= 10 Character
DATE CONVERSIONS:
D @YMD S 6S 0
D @YMD8
S 8S 0
D @MDY S 6S 0
D @MDY8
S 8S 0
D @Date S D DATFMT(*ISO)
Put The Current Date In A Date Field
Eval @Date = %Date()
Convert A 6 Digit Signed Date To A Date Field
MMDDYY to
YYYY-MM-DD
Eval @Date = %Date(@MDY:*MDY)
YYMMDD to
YYYY-MM-DD
Eval @Date = %Date(@YMD:*YMD)
Convert a 8 digit signed date to a Date field
MMDDYYYY
to YYYY-MM-DD
Eval @Date = %Date(@MDY8:*USA)
YYYYMMDD
to YYYY-MM-DD
Eval @Date = %Date(@YMD8:*ISO)
Move A Date Field To A 6 Digit Signed Field
Eval @MDY = %Dec(@Date:*MDY)
Eval @YMD = %Dec(@Date:*YMD)
Move A Date Field To A 8 Digit Signed Field
Eval @MDY8 = %Dec(@Date:*USA)
Eval @YMD8 = %Dec(@Date:*ISO)
Convert a
6 digit signed date in MMDDYY format to a YYMMDD format
Eval @YMD = %Dec(%Date(@MDY:*MDY):*YMD)
Convert A 6 Digit Signed Date In YYMMDD Format To A MMDDYY
Format
Eval @MDY = %Dec(%Date(@YMD:*YMD):*MDY)
Convert A 6 Digit Signed Date Into An 8 Digit Signed Date
MMDDYY to
MMDDYYYY
Eval @MDY8 = %Dec(%Date(@MDY:*MDY):*USA)
MMDDYY to
YYYYMMDD
Eval @YMD8 = %Dec(%Date(@MDY:*MDY):*ISO)
YYMMDD to
MMDDYYYY
Eval @MDY8 = %Dec(%Date(@YMD:*YMD):*USA)
YYMMDD to
YYYYMMDD
Eval @YMD8 = %Dec(%Date(@YMD:*YMD):*ISO)
Convert A 8 Digit Signed Date Into An 6 Digit Signed Date
MMDDYYYY
to MMDDYY
Eval @MDY = %Dec(%Date(@MDY8:*USA):*MDY)
MMDDYYYY
to YYMMDD
Eval @YMD = %Dec(%Date(@MDY8:*USA):*YMD)
YYYYMMDD
to MMDDYY
Eval @MDY = %Dec(%Date(@YMD8:*ISO):*MDY)
YYYYMMDD
to YYMMDD
Eval @YMD = %Dec(%Date(@YMD8:*ISO):*YMD)
DATE CONVERSIONS IN FREE FORMAT:
H
option(*nodebugio)
D @charA S 8 inz('04/12/01')
D @charB S 10 inz('12/02/2004')
D @charC S 8 inz('12/03/04')
D @dateA S d inz(D'2004-12-04')
D @numA S 6
0 inz(041205)
D @numB S 7
0 inz(1041206)
D @numC S 8
0 inz(20041207)
D @numD S 6
0 inz(120804)
D @numE S 8
0 inz(12092004)
/free
// character
to character...
@charB
= %char(%date(@charA:*ymd/):*usa/); // 'yy/mm/dd' to
'mm/dd/ccyy'
@charC
= %char(%date(@charA:*ymd/):*mdy/);
// 'yy/mm/dd' to 'mm/dd/yy'
@charA
= %char(%date(@charB:*usa/):*ymd/); // 'mm/dd/ccyy' to 'yy/mm/dd'
@charC
= %char(%date(@charB:*usa/):*mdy/); // 'mm/dd/ccyy' to
'mm/dd/yy'
@charA
= %char(%date(@charC:*mdy/):*ymd/);
// 'mm/dd/yy' to 'yy/mm/dd'
@charB
= %char(%date(@charC:*mdy/):*usa/); // 'mm/dd/yy' to
'mm/dd/ccyy'
// character
to date...
@dateA = %date(@charA:*ymd/); // 'yy/mm/dd' to
D'ccyy-mm-dd'
@dateA = %date(@charB:*usa/); // 'mm/dd/ccyy' to
D'ccyy-mm-dd'
@dateA = %date(@charC:*mdy/); // 'mm/dd/yy' to D'ccyy-mm-dd'
// character
to numeric...
@numA
= %dec(%char(%date(@charA:*ymd/):*ymd0):6:0); // 'yy/mm/dd' to
yymmdd
@numB
= %dec(%char(%date(@charA:*ymd/):*cymd0):7:0); // 'yy/mm/dd' to
cyymmdd
@numC
= %dec(%char(%date(@charA:*ymd/):*iso0):7:0); //
'yy/mm/dd' to ccyymmdd
@numD
= %dec(%char(%date(@charA:*ymd/):*mdy0):7:0); // 'yy/mm/dd' to
mmddyy
@numE
= %dec(%char(%date(@charA:*ymd/):*usa0):7:0); //
'yy/mm/dd' to mmddyyyy
@numA
= %dec(%char(%date(@charB:*usa/):*ymd0):6:0); //
'mm/dd/ccyy' to yymmdd
@numB = %dec(%char(%date(@charB:*usa/):*cymd0):7:0); // 'mm/dd/ccyy' to
cyymmdd
@numC
= %dec(%char(%date(@charB:*usa/):*iso0):7:0); // 'mm/dd/ccyy' to ccyymmdd
@numD
= %dec(%char(%date(@charB:*usa/):*mdy0):7:0); // 'mm/dd/ccyy' to
mmddyy
@numE
= %dec(%char(%date(@charB:*usa/):*usa0):7:0); //
'mm/dd/ccyy' to mmddyyyy
@numA = %dec(%char(%date(@charC:*mdy/):*ymd0):6:0); // 'mm/dd/yy' to yymmdd
@numB
= %dec(%char(%date(@charC:*mdy/):*cymd0):7:0); // 'mm/dd/yy' to
cyymmdd
@numC
= %dec(%char(%date(@charC:*mdy/):*iso0):7:0); //
'mm/dd/yy' to ccyymmdd
@numD
= %dec(%char(%date(@charC:*mdy/):*mdy0):7:0); // 'mm/dd/yy' to
mmddyy
@numE
= %dec(%char(%date(@charC:*mdy/):*usa0):7:0); //
'mm/dd/yy' to mmddyyyy
// date to
character...
@charA = %char(@dateA:*ymd/); // D'ccyy-mm-dd' to 'yy/mm/dd'
@charB = %char(@dateA:*usa/); // D'ccyy-mm-dd' to 'mm/dd/ccyy'
@charC = %char(@dateA:*mdy/); // D'ccyy-mm-dd' to
'mm/dd/yy'
// date to
numeric...
@numA
= %dec(%char(@dateA:*ymd/):6:0); // D'ccyy-mm-dd' to
yymmdd
@numB
= %dec(%char(@dateA:*cymd/):7:0); //
D'ccyy-mm-dd' to cyymmdd
@numC
= %dec(%char(@dateA:*iso-):8:0); // D'ccyy-mm-dd' to
ccyymmdd
@numD
= %dec(%char(@dateA:*mdy/):6:0); // D'ccyy-mm-dd' to
mmddyy
@numE
= %dec(%char(@dateA:*usa/):8:0); // D'ccyy-mm-dd' to
mmddccyy
// numeric to
character...
@charA
= %char(%date(@numA:*ymd):*ymd/); // yymmdd to
'yy/mm/dd'
@charB
= %char(%date(@numA:*ymd):*usa/); // yymmdd to
'mm/dd/ccyy'
@charC
= %char(%date(@numA:*ymd):*mdy/); // yymmdd to
'mm/dd/yy'
@charA
= %char(%date(@numB:*cymd):*ymd/); // cyymmdd to
'yy/mm/dd'
@charB
= %char(%date(@numB:*cymd):*usa/); // cyymmdd to
'mm/dd/ccyy'
@charC
= %char(%date(@numB:*cymd):*mdy/); // cyymmdd to
'mm/dd/yy'
@charA
= %char(%date(@numC:*iso):*ymd/); // D'ccyy-mm-dd' to
'yy/mm/dd'
@charB
= %char(%date(@numC:*iso):*usa/); // D'ccyy-mm-dd' to
'mm/dd/ccyy'
@charC
= %char(%date(@numC:*iso):*mdy/); // D'ccyy-mm-dd' to
'mm/dd/yy'
@charA = %char(%date(@numD:*mdy):*ymd/); // mmddyy to
'yy/mm/dd'
@charB
= %char(%date(@numD:*mdy):*usa/); // mmddyy to
'mm/dd/ccyy'
@charC
= %char(%date(@numD:*mdy):*mdy/); // mmddyy to
'mm/dd/yy'
@charA
= %char(%date(@numE:*usa):*ymd/); // mmddccyy to
'yy/mm/dd'
@charB
= %char(%date(@numE:*usa):*usa/); // mmddccyy to
'mm/dd/ccyy'
@charC
= %char(%date(@numE:*usa):*mdy/); // mmddccyy to
'mm/dd/yy'
// numeric to
date...
@dateA = %date(@numA:*ymd); // yymmdd to
D'ccyy-mm-dd'
@dateA = %date(@numB:*cymd); // cyymmdd to
D'ccyy-mm-dd'
@dateA = %date(@numC:*iso); // ccyymmdd' to
D'ccyy-mm-dd'
@dateA = %date(@numD:*mdy); // mmddyy to
D'ccyy-mm-dd'
@dateA = %date(@numE:*usa); // mmddccyy to
D'ccyy-mm-dd'
//
numeric to numeric...
@numB
= %dec(%char(%date(@numA:*ymd):*cymd0):7:0); //
yymmdd to cyymmdd
@numC
= %dec(%char(%date(@numA:*ymd):*iso0):8:0); // yymmdd
to ccyymmdd
@numD = %dec(%char(%date(@numA:*ymd):*mdy0):6:0); // yymmdd to
mmddyy
@numE
= %dec(%char(%date(@numA:*ymd):*usa0):8:0); // yymmdd to
mmddccyy
@numA
= %dec(%char(%date(@numB:*cymd):*ymd0):6:0); // cyymmdd to
yymmdd
@numC
= %dec(%char(%date(@numB:*cymd):*iso0):8:0); // cyymmdd to
ccyymmdd
@numD
= %dec(%char(%date(@numB:*cymd):*mdy0):6:0); // cyymmdd to
mmddyy
@numE
= %dec(%char(%date(@numB:*cymd):*usa0):8:0); // cyymmdd to
mmddccyy
@numA
= %dec(%char(%date(@numC:*iso):*ymd0):6:0); // ccyymmdd
to yymmdd
@numB
= %dec(%char(%date(@numC:*iso):*cymd0):7:0); // ccyymmdd to
cyymmdd
@numD
= %dec(%char(%date(@numC:*iso):*mdy0):6:0); // ccyymmdd
to mmddyy
@numE
= %dec(%char(%date(@numC:*iso):*usa0):8:0); // ccyymmdd
to mmddccyy
@numA
= %dec(%char(%date(@numD:*mdy):*ymd0):6:0); // mmddyy to
yymmdd
@numB
= %dec(%char(%date(@numD:*mdy):*cymd0):7:0); //
mmddyy to cyymmdd
@numC
= %dec(%char(%date(@numD:*mdy):*iso0):8:0); // mmddyy to
ccyymmdd
@numE
= %dec(%char(%date(@numD:*mdy):*usa0):8:0); // mmddyy to
mmddccyy
@numA = %dec(%char(%date(@numE:*usa):*ymd0):6:0); // mmddccyy to
yymmdd
@numB
= %dec(%char(%date(@numE:*usa):*cymd0):7:0); // mmddccyy to
cyymmdd
@numC
= %dec(%char(%date(@numE:*usa):*iso0):8:0); // mmddccyy
to ccyymmdd
@numD = %dec(%char(%date(@numE:*usa):*mdy0):6:0); // mmddccyy to
mmddyy
*inlr = *on;
No comments