HOME

FORUM

UPLOAD SOURCE

RPGLE/RPG

CLLE

SQLRPGLE

DDS

API

OTHER

JAVA

IFS

HTML

JAVA SCRIPT

PHP

MYSQL

XML

OLE DB







Date operations allow you to work with dates, times, and timestamp fields
and character or numeric fields that represent dates, times, and 
timestamps.
You can: 
  • Add or subtract a duration in years, months, days, hours, minutes, seconds, or microseconds
  • Determine the duration between two dates, times, or timestamps
  • Extract a portion of a date, time, or timestamp (for example, the day)
  • Test that a value is valid as a date, time, or timestamp.
  • To add or subtract a duration, you can use the + or - operator in free-form
  • syntax or the ADDDUR or SUBDUR operation code in traditional syntax.
  • The code below shows the built-in functions that you use in free-form syntax and the duration codes that you use in traditional syntax.

    Various Date Calculations

    OBJECTS
    DATE        RPGLE       Show various date processes.
    



    DOWNLOAD
    Download text files

    Built in functions used with date processing

    %MSeconds    Retrieve milliseconds from formatted date
    %Seconds     Retrieve seconds from formatted date
    %Minutes     Retrieve minutes from formatted date
    %Hours       Retrieve hours from formatted time
    %Days        Retrieve days from formatted date
    %Months      Retrieve months from formatted date
    %Years       Retrieve years from formatted date
    %Date        Retrieve the date        
    %Time        Retrieve the time
    %TimeStamp   Retrieve a time stamp
    %Subdt       Substring year, month or day from formatted date
    %Char        Use a decimal field in a substring function
    
         
        Define Date Variables All date formats without keyword
    	DatFmt will default to *ISO.  '2003-09-23'
    	When you initialize a date field you must prefix the
    	date with the letter "D" see below.
         D*---------------------------------------------------------
         D*  Field Definitions.
         D*---------------------------------------------------------
         D                SDS
         D  @PGM                 001    010
         D  @PARMS               037    039  0
         D  @JOB                 244    253
         D  @USER                254    263
         D  @JOB#                264    269  0
         D*
         D*  Field Definitions.
         D*
         D ISOdate         S               D
         D USAdate         S               D   DatFmt(*USA)
         D XMASDate        S               D   Inz(D'2003-12-25')
         D LogonDate       S               D
         D Date_Start      S             15
         D MonthNames      S             12    Dim(12) CtData
         D Date_String     S             40
          *
          * Time Stamp
          *
         DTimeStamp        S               Z
          *
         D WorkISO         S               D
         D Month           S              2  0
         D Day             S              2  0
         D Year            S              4  0
         D Decimal8        S              8  0
         D LogMonth        S              2  0
         D LogDay          S              2
         D LogYear         S              4  0
         D NextMonth       S               D
         D EndOfMonth      S               D
          *
          * Variables for free RPG example + some above
          *
         D DateIn          S               D
         D FromISO         S               D
         D ToISO           S               D
         D DiffDays        S              3  0
         D WorkField       S              5  0
         D Name            S              9    Based(NamePtr)
         D Name2           S              9
         D NamePtr         S               *   Inz(%ADDR(Names))
         D Names           S             63    Inz('Sunday   Monday   Tuesday  Wedn+
         D                                     esdayThursday Friday   Saturday ')
         
          *-----------------------------------------------------------
          * RPG-defined date formats and separators for Date data type
          *-----------------------------------------------------------
          * 2-Digit Year Formats
          * *MDY  Month/Day/Year  mm/dd/yy  8  09/26/03
          * *DMY  Day/Month/Year  dd/mm/yy  8  26/09/03
          * *YMD  Year/Month/Day  yy/mm/dd  8  03/09/26
          * *JUL  Julian          yy/ddd    6  03/926
          *----------------------------------------------------------
          * 4-Digit Year Formats
          * *ISO  Int Standards Org yyyy-mm-dd  10  2003-09-26
          * *USA  IBM USA Standard  mm/dd/yyyy  10  09/26/2003
          * *EUR  IBM European Std  dd.mm.yyyy  10  26.09.2003
          * *JIS  Japan Indst Std   yyyy-mm-dd  10  2003-09-26
          *
          *
          *----------------------------------------------------------
          
    	  
    	  
    	  
    	  *
          * Okay first lets get todays date
          * For display purposes the date is now
          *      Friday September 26th 2003
          *  so date now looks like this 2003-09-26
          *  because the default date type is *ISO
          *
         C                   Eval      ISOdate = %Date()
    	 
    	 
    	 
          *
          *  Now that I have the date in a date format
          *  (*ISO) I can do stuff to it.
          *  Once I move this date to a decimal 8,0 field
          *  the date is now in format 20030926
          *  Not very exciting..yet
          *
         C                   Move      ISODate       Decimal8
    	 
    	 
    	 
          *
          *  Now back to the *ISO date  lets add
          *  1 month to the date.
          *  date after will equal 2003-10-26
          *  %days and %years works the same as %months
          *
         C                   Eval      WorkISO  = ISODate + %Months(1)
    	 
    	 
          *
          *  Logon date is set equal to today then the month is extracted
          *  the "*M" is the same as "*Months"  LogMonth = 09.
          *                                     LogDay   = 26.
          *
         C                   Eval      LogonDate =  %Date()
         C                   Extrct    LogonDate:*Y  LogYear
         C                   Extrct    LogonDate:*M  LogMonth
         C                   Extrct    LogonDate:*D  LogDay
          *
          *  Build the date string - Later we will add the day name
          *
         D MonthNames      S             12    Dim(12) CtData
    	 
    	 
         C                   Eval      Date_String =
         C                              %Trim(MonthNames(LogMonth))
         C                              + %trim('@') + %Trim(LogDay)
         C                              + %trim(',@') + %Char(LogYear)
          
         C*----------------------------------------------------
    ** CTDATA MonthNames
    January
    February
    March
    April
    May
    June
    July
    August
    September
    October
    November
    December
    	  
          *
          *  convert the "@" back to *Blanks
          *  Date_String = 'September 26, 2003'
          *
         C     '@':' '       Xlate     Date_String   Date_String
          *
          * TimeStamp = yyyy-mm-dd-hh.mm.ss.mmmmmm (length 26).
          * TimeStamp = '2003-09-26-15.16.26.531000'
          *
         C                   Eval      TimeStamp = %TimeStamp()
          *
          *  Free Format date stuff   By the way Name2 = 'Friday'
          *
          /Free
            DateIn   = %Date()                     ;
            ISODate  = %Date()                     ;
            ISODate  = DateIn                      ;
            Year     = %Subdt(ISODate:*Y)          ;
            Month    = %Subdt(ISODate:*M)          ;
            Day      = %Subdt(ISODate:*D)          ;
            FromISO  = ISODate - %YEARS(1)         ;
            ToISO    = ISODate                     ;
            DiffDays = %Diff(ToISO:FromISO:*DAYS)  ;
            ISODate  = DateIn                      ;
    
            WorkField = %Diff(ISODate:D'1899-12-31':*DAYS);
            WorkField = %REM(WorkField:7);
    
            NamePtr = NamePtr + (WorkField * 9);
            Name2 = Name;
          /End-Free
          *
          *  Build the date string - With The Day Name
          *  DATE_STRING = 'Friday  September 26, 2003              '
          *
         C                   Eval      Date_String =
         C                              %trim(Name) + %Trim('@@')
         C                              + %trim(MonthNames(LogMonth))
         C                              + %trim('@') + %Trim(LogDay)
         C                              + %trim(',@') + %Char(LogYear)
         C                   Eval      Date_String = %Xlate('@':' ':Date_String)
          *
          * Calculate the last day of the month
          * ENDOFMONTH = '2003-09-30'
          *
         C     ISODate       AddDur    1:*Months     NextMonth
         C                   Extrct    NextMonth:*D  DiffDays
         C     NextMonth     SubDur    DiffDays:*D   EndOfMonth
    
    
         C                   Eval      *INLR = *On
    	 
          


    	 V5R2
         /free
    	   numDate = %int(%char(date : *eur0);  //  ddmmyyyy
    	   numTS = %dec(%char(timestamp : *iso0) : 20 : 0);   //yyyymmddhhmmssuuuuuu
         /End Free
    	 


    V5R1 H bnddir('QC2LE') D atoll pr 20i 0 extproc('atoll') D string * value options(*string) /free numDate = atoll(%char(date : *eur0)); /End Free



    /free // Convert Date from ccyymmdd to mmddyy Sdt = %uns(%char(%Date(#SoSdt:*Iso):*Mdy0)); // Todays Date in Ccyymmdd format Today = %uns(%char(%Date():*Iso0)); // Convert From Julian to ccyymmdd CbpPayDte = %Dec(%Char(%Date(%Subst(%Editc(Rpdgj:'X'):2:5) :*Jul0):*Iso0):8:0);

Examples posted by visitors




     Posted by: Reynoo Moore - CLLE convert date to Julian   

  PGM
DCL &DATE6 *CHAR LEN(6)
DCL &DATE5 *CHAR LEN(5)
RTVSYSVAL QDATE RTNVAR(&DATE6)
CVTDAT DATE(&DATE6) TOVAR(&DATE5) TOFMT(*JUL) TOSEP(*NONE)
ADDPFM LIB1/FILEX MBR(’MBR’ *CAT &DATE5)
.
.
.
ENDPGM

 or use a c function

The following is an alternative program that uses the ILE bindable API, Get
Current Local Time (CEELOCT), to convert a date to Julian format. To create 
this
program, you must use the CRTBNDCL command alone or the CRTCLMOD
command and the CRTPGM command together.
PGM
     DCL &LILDATE *CHAR LEN(4)
     DCL &PICTSTR *CHAR LEN(5) VALUE(YYDDD)
     DCL &JULDATE *CHAR LEN(5)
     DCL &SECONDS *CHAR 8 /* Seconds from CEELOCT */
     DCL &GREG *CHAR 23 /* Gregorian date from CEELOCT */
/* */
          CALLPRC PRC(CEELOCT) /* Get current date and time */ +
          PARMS (&LILDATE)   /* Date in Lilian format */ +
                        &SECONDS /* Seconds field will not be used */
                        &GREG       /* Gregorian field will not be used */
                         *OMIT         /* Omit feedback parameter so 
exceptions +
                                              are signalled */

         CALLPRC PRC(CEEDATE) +
         PARMS (&LILDATE) /* Today’s date */ +
                       &PICTSTR /* How to format */ +
                       &JULDATE /* Julian date */ +
                       *OMIT

        ADDPGM LIB1/FILEX MBR(’MBR’ *CAT &JULDATE’)
        ENDPGM

 

     Posted by: Denny - Open Query File   

 OPNQRYF has very powerful date functions. Assuming you DB dates are L data 
type:
  QRYSLT('IFPDT < (%CURDATE - %DURMONTH(6))') /* Select records over 6 months 
old. */        
                                                                           
  QRYSLT('LBADT *LT (%CURDATE - %DURDAY(35))') /* Select over 35 days old. 
*/                         

     Posted by: Mike Noun - Free format add 5 days to date   

   *    =================================================================
      *    = Definitions                                                   =
      *    =================================================================

     D CharDate        DS
     D  NumericDate                   8S 0
     D ISODate         S               D   DatFmt( *ISO )

      /Free

      //   =================================================================
      //   = Add 5 days to numeric date field using the following steps.   =
      //   =                                                               =
      //   = 1. Use %Date and %Days BIFs to create a date field from the   =
      //   =    numeric field and add 5 days to the date field             =
      //   = 2. Use %Char to convert the date field to character data      =
      //   =    structure that contains the numeric field                  =
      //   =================================================================

          ISODate = %Date( NumericDate ) + %Days( 5 ) ;
          CharDate = %Char( ISODate : *ISO0 ) ;

      /End-Free 

     Posted by: Jeffrey Flaker - Date data structure   

  Datastructure
 
D DataStructure   DS
D  FullDate                    10
D   YYYY                        4  0 overlay(FullDate)
D   FirstDash                   1    overlay(FullDate:*next)  
D   MM                          2  0 overlay(FullDate:*next)
D   SecondDash                  1    overlay(FullDate:*next)  
D   DD                          2  0 overlay(FullDate:*next)  
 
 

     Posted by: Birgitta - SQL date difference   

  if you want do calculate the difference in either years or months or 
days,
use the OpCode SUBDUR or Built-in-Function %Diff(Date1: Date2: Time 
Code)

C     Date1         subdur    Date2         DiffDays:*D
C                   eval      DiffDays   = %Diff(Date1: Date2: *Days)

if you want to calculate the difference in years and months and days,
use SQL.
When substracting two date fields from each other with SQL, your result
numeric field with the following content.
Position 1-4 = years
Position 5-6 = months
Position 7-8 = days

D                 DS
D DiffDate                       8  0
D   DiffYears                    4  0 overlay(DiffDate)
D   DiffMonths                   2  0 overlay(DiffDate: *Next)
D   DiffDays                     2  0 overlay(DiffDate: *Next)

D Date1           S               D   inz(D'2004-07-01')
D Date2           S               D   inz(D'2003-01-31')

c/EXEC SQL
C+    set :DiffDate  = :Date1 - :Date2
c/END-EXEC

DiffDate = 10501 --> 1 year, 5 months and 1 day
 

     Posted by: Werner Noll / Retrieve end of month date (last day   

 
#DateISO        S               D   DatFmt(*ISO)
/Free

// Retrieve end of month date (last day of month)                         
//  %date() may be replaced by any date field                             
#DateISO=(%date()+%months(1))-%days(%subdt((%date()+%months(1)):*days));  

/end-free 

     Posted by: jimmy/Convert 033104 to 20040331   

  H DftActGrp(*No) Option(*SrcStmt : *NoDebugIO)             
 * Convert 033104 to 20040331                              
d dateMDY         S            006  0 inz(033104)          
d Isodate         S               D                        
d dateCYMD        S            008  0                      
d reply           S            001                         
d chr8            S            008                         
c     *MDY          test(de)                DateMDY        
c                   if        not%Error                    
c     *MDY          move      DateMDY       Isodate        
c                   move      Isodate       dateCYMD       
c                   move      dateCYMD      Chr8           
c     Chr8          dsply     reply                        
c                   endif                                  
c                   eval      *inlr = *On                  
****************** End of data **************************** 

     Posted by: Dmitriy Margolin / Date conversion from Char to Nu   

                                
D  Date_Num                      8S 0 Inz               
D  Date_Char                     8A   Overlay(Date_Num) 
 *******************************************************
 * If numeric date needed and not able to use C function  
 * can be used if system is prior to V5R2
 *******************************************************
 /Free                                                  
                                                        
    Date_Char = %Char(%Date(): *Iso0) ;  
    Date_Char = %Char(%Date() - %Days(7): *Iso0) ;

   // after this opereation Date_Num will containt current or week ago day 
   // in numeric format.
                                                        
/End-Free                                                  

                                                         

     Posted by: Bob Cozzi - extracted from MC Press Online   

 Date processing continues to be a pain in the neck for many RPG programmers. 
RPG III still does not support true date fields, while RPG IV and DDS do. 
Consequently, those who have not moved their entire set of applications to RPG 
IV have decided to not use date fields in their database files.

In V5R2, IBM added a date format code to the %CHAR built-in function that 
allows you to specify the resulting format of the date value that is 
generated. 
In V5R3, IBM has added the capability to convert a numeric value into a date 
value and specify the format that the value is stored in. The %DATE built-in 
function now converts a numeric value into a date value. The second parameter 
of %DATE allows you to specify the format of the non-date value that you are 
converting. This allows you to compare or assign a non-date value to a true 
date variable. 

Prior to V5R2, you had to use the MOVE operation code to convert the non-date 
value to a true date field and then use that field to compare. 

While things are getting easier, it would still be beneficial if IBM would add 
true date data-type support to the RPG III language. But don't hold your 
breath. 

The following are examples of the techniques explained above:

     D Today           S               D   Datfmt(*JUL)
     D DueDate2        S               D   Datfmt(*ISO)
     D dueDate         S              8S 0
      
      /IF DEFINED(*V5R3M0)
     C                   if        %Date(dueDate:*ISO) > Today
      /ELSEIF DEFINED(*V5R2M0)
     C                   if        %int(%Char(dueDate)) > 
     C                                %Int(%char(NewDate:*ISO0))
      /ELSE
     C     *ISO0         MOVE      dueDate       dueDate2
     C                   if        dueDate2 > Today
      /ENDIF
 

     Posted by: sanjib kumar behera/evaluate next friday from any   

  Hdatfmt(*usa)                                                         
Ddatein           s               d   datfmt(*iso)                    
D                                     inz(*sys)                       
Ddatetest         s               d   datfmt(*iso)                    
D                                     inz(d'01/04/1980')              
C                                                                     
C                   DSPLY                   DATE              6 0     
C     date          ifne      *zeros                                  
C     *mdy          TEST(D)                 DATE                   99 
C     *IN99         IFEQ      *OFF                                    
C     *MDY          MOVE      DATE          DATEIN                    
C                   ENDIF                                             
C                   ENDIF                                             
C                                                                     
C     DATEIN        SUBDUR    DATETEST      DAYS:*D           7 0     
C     DAYS          DIV       7             DAYS                    
C                   MVR                     INDEX             1 0   
C     7             SUB       INDEX         INDEX                   
C                   ADDDUR    INDEX:*D      DATEIN                  
C     *MDY          MOVE      DATEIN        DATE                    
C     DATE          DSPLY                                           
            
c                   EVAL      *INLR=*ON                              

     Posted by: sanjib kumar behera/color program   

 PGM                                                                
DCL        VAR(&S)     TYPE(*CHAR) LEN(70)                         
DCL        VAR(&S1)    TYPE(*CHAR) LEN(70)                         
DCL        VAR(&S2)    TYPE(*CHAR) LEN(70)                         
DCL        VAR(&S3)    TYPE(*CHAR) LEN(70)                         
DCL        VAR(&L) TYPE(*CHAR) LEN(1) VALUE(X'20')                 
DCL        VAR(&C1)     TYPE(*CHAR) LEN(1) VALUE(X'30')            
DCL        VAR(&C2)     TYPE(*CHAR) LEN(1) VALUE(X'31')            
DCL        VAR(&C3)     TYPE(*CHAR) LEN(1) VALUE(X'32')            
CHGVAR VAR(&S) VALUE('COLOR. SANJIB KUMAR BEHERA ')                
CHGVAR     VAR(&S1)  VALUE(&C1 *CAT &S *TCAT &L *TCAT ' - COLOR 1')
CHGVAR     VAR(&S2)  VALUE(&C2 *CAT &S *TCAT &L *TCAT ' - COLOR 2')
CHGVAR     VAR(&S3)  VALUE(&C3 *CAT &S *TCAT &L *TCAT ' - COLOR 3')
SNDUSRMSG  MSG(&S1)  MSGTYPE(*INFO) TOMSGQ(*EXT)                   
SNDUSRMSG  MSG(&S2)  MSGTYPE(*INFO) TOMSGQ(*EXT)                   
SNDUSRMSG  MSG(&S3)  MSGTYPE(*INFO) TOMSGQ(*EXT)                   
ENDPGM   

     Posted by: Doug Eckersley - More date processing   

  Deriving the Day of Week 

DoWk = %rem(%diff(MyDate:d’0001-01-nn’:*d) : 7) + 1;

To return a number based on 1=Monday, use 01 for nn. For 1=Sunday, use 07 for 
nn.

Changing a Component of a Date
RPG does not have a facility to easily change a component of a date, so if you 
do not want to use an overlapping data structure with a pointer, you can use 
expressions such as the following:

To change the day to n:

ResultDate = MyDate - %days(%subdt(MyDate:*d) - 1) + %days(n - 1);

Make sure MyDate has n days, or else ResultDate will be a date in the 
following month.

To change the month to n:

ResultDate = MyDate - %months(%subdt(MyDate:*m) - 1) + %months(n - 1);

To change the year to n:

ResultDate = MyDate - %years(%subdt(MyDate:*m) - 1) + %months(n - 1);

In changing the day or month, it would generally be safe to omit the "- 1" 
factor. It will be needed, however, when changing the components of a date 
initially set to *LOVAL.

Extracting Multiple Components of a Date into One Field
This requires a little mathematics. As an example, to get the month and day 
into one numeric field, do this:


MonthDay = (%subdt(MyDate:*m) * 100) + %subdt(MyDate:*d);

Think of the zeros as place holders for all of the following components. This 
method of extracting multiple components is required to convert a date to 
numeric in pure RPG prior to V5R2, like so:


NumericISO = (%subdt(MyDate:*y) * 10000) +
             (%subdt(MyDate:*m) * 100)   +
             (%subdt(MyDate:*d);

or


NumericUSA = (%subdt(MyDate:*m) * 1000000) +
             (%subdt(MyDate:*d) * 10000)   +
             (%subdt(MyDate:*y);

Changing the Day of a Date to the First of the Month

ResultDate = MyDate - %days(%subdt(MyDate:*d) – 1);

Changing the Day of a Date to the Last of the Month

ResultDate = MyDate - %days(%subdt(MyDate:*d) – 1) + %months(1) - %days(1);

Changing the Day of a Date to the First of the Year

ResultDate = MyDate - %months(%subdt(MyDate:*m) – 1) –
%days(%subdt(MyDate:*d)- 1);

or


ResultDate = d'0001-01-01' + %years(%subdt(MyDate:*y) - 1)

Determining What Quarter a Date Is In

Quarter = %div(%subdt(MyDate:*m) – 1 : 3) + 1;

Determining the First Date of a Quarter
The year has to be known. The day will be 1. The month is determined with this 
code:


((Quarter – 1) * 3) + 1

Determining the Last Date of a Quarter

ResultDate = FirstDate + %months(4) - %days(1);

Deriving a Date from a J.D. Edwards (CYYJJJ) Date

ResultDate = %date(JDEDate + 1900000 : *longjul);

Deriving a J.D. Edwards Date from a Date:

JDEDate = %int(%char(MyDate:*longjul0)) – 1900000;

Deriving the Julian Day
Issuing a %subdt or extrct on a Julian formatted date will return the 
Gregorian day. To get the Julian day, try this expression:


%diff(MyDate-%days(%subdt(MyDate:*d)) :                   
      d'0001-01-01' + %years(%subdt(MyDate:*y) - 1) : 
      *d)
+ %subdt(MyDate:*d)
+ 1;                                     

This expression should operate on MyDate, regardless of its format, Julian or 
otherwise.

Deriving a Calendar Duration
A calendar duration is defined as the duration between two dates in years, 
months, and days. Date1 should be after Date2 (chronologically speaking).


Years = %diff(Date1:Date2:*y);
Date1 -= %years(Years);
Months = %diff(Date1:Date2:*m);
Date1 -= %months(Months);
Days = %diff(Date1:Date2:*d);

Converting Character or Numeric Fields to Date


MyDate = %date(MyField:);

Converting Date to Character


MyChar = %char(MyDate:);

Converting Date to Numeric


MyNumeric = %int(%char(MyDate:));

The desired return format should not have separators, so place a 0 following 
the format, e.g., *iso0, *usa0, etc. You can also use %uns or %dec instead of %
int.

Converting a Non-Date Data Type Field Containing a Date from One Format to 
Another


TargetDate = %char(%date(SourceDate:):);

SourceDate can be character or numeric. This expression would return a 
character date. To return a numeric date, enclose the expression in an %int, %
uns, or %dec. Be sure that the desired format does not contain separators.

 

     Posted by: Jason / useful date conversions   

 **********************************************************************
* character dates
d @chara          s              8    inz('04/12/01')
d @charb          s             10    inz('12/02/2004')
d @charc          s              8    inz('12/03/04')
**********************************************************************
* date field
d @datea          s               d   inz(d'2004-12-04')
**********************************************************************
* numeric dates
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 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
@numd = %dec(%char(%date(@chara:*ymd/):*mdy0):7:0); //'yy/mm/dd' to mmddyy
@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
@numd = %dec(%char(%date(@charb:*usa/):*mdy0):7:0); //'mm/dd/ccyy' to mmddyy
@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
@numd = %dec(%char(%date(@charc:*mdy/):*mdy0):7:0); //'mm/dd/yy' to mmddyy

//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'

//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;

/end-free








 

     Posted by: chris hayden - %timestamp   

 D                 DS                                         
D TimeStamp                       z                          
D Cur_Date                        d   Overlay(TimeStamp)     
D Cur_Time                        t   Overlay(TimeStamp:12)  

timeStamp =  %Timestamp;   

  

     Posted by: Midrange - Date Free form example(s)   

 DoWk = %rem(%diff(MyDate:d’0001-01-nn’:*d) : 7) + 1;
ResultDate = MyDate - %days(%subdt(MyDate:*d) - 1) + %days(n - 1);
ResultDate = MyDate - %months(%subdt(MyDate:*m) - 1) + %months(n - 1);
ResultDate = MyDate - %years(%subdt(MyDate:*m) - 1) + %months(n - 1);
MonthDay = (%subdt(MyDate:*m) * 100) + %subdt(MyDate:*d);
  

     Posted by: Birgitta Hauser - get next fridays date with sql   

  The following example shows how next Friday can be determined with SQL.

D NextFriday      S               D  
D DayWeek         S              5I 0
*----------------------------------------------------------------------
C/EXEC SQL set Option  DatFmt = *ISO    
c/END-EXEC                              

C/EXEC SQL set :DayWeek = DayOfWeek_Iso(Current_Date)   
c/END-EXEC

C+ set :NextFriday = Current_Date +                              
C+                   case when :DayWeek <= 5 then 5 - :DayWeek
c+                        when :DayWeek  = 6 then 6           
C+                        when :DayWeek  = 7 then 5           
C+                   End  Days                                
C/END-EXEC   

     Posted by: Jamie - Some *CYMD conversions   

       *=======================================================================
      *
      *  Field Definitions.
      *
      *=======================================================================
      
     d CharDate7       s              7
     d InDate          s             15  5
     d ISODate         s               D
     d WorkDate7       s              7  0
     d WorkDate8       s              8  0
     d Reply           s              1
      *
      * If date passed in convert it to *CYMD if not passed in use
      * todays date in *ISO and convert to *CYMD.
      *
     c     *Entry        plist
     c                   parm                    InDate
      *
     c                   if        %parms >= 1
     c                   z-add     InDate        WorkDate8
     c                   eval      WorkDate7 =
     c                             %uns(%char(%Date(%char(WorkDate8):*ISO0)
     c                             :*Cymd0))
     c                   else
     c                   eval      WorkDate7 =
     c                             %uns(%char(%Date():*cymd0))
     c                   endif
      *
     c                   eval      CharDate7 = %char(WorkDate7)
      *
     c     CharDate7     dsply                   reply
      *
     c                   eval      *INLR = *on  

     Posted by: Pedro Molina - Convertion from Julian Date to ISO   

 *--------------------------------------------------------------*
* Code                                                         *
*--------------------------------------------------------------*
D ISODATE         S               D   DATFMT(*iso)
D JULDATE         S              5S 0 INZ(05144) 

* JULDATE CONTAINS A JULIAN DATE FORMAT, 05 REFFERS TO THE YEAR AND 144 IS THE 
NUMBER OF TRANSCURRED DAYS.

/FREE
   ISODATE = %DATE(); // ISODATE RECEIVES THE SYSTEM DATE
   ISODATE = %DATE(JULDATE:*JUL0) // ISODATE RECEIVES JULDATE
/END-FREE

* THE NEW VALUE FOR ISODATE IS '2005-05-24'



 

     Posted by: missing bracket!   

 numDate = %int(%char(date : *eur0);  //  ddmmyyyy

should be 

numDate = %int(%char(date : *eur0));  //  ddmmyyyy
	    

     Posted by: babu@efunds - -> To Calculate Prev Month Start Dat   

 ****************************************************
* To Calculate Previous month Start & End Date     
****************************************************

D CurDate         S               D   Inz(D'2005-03-31')
D TD              S               D                                
D FD              S               D            
 * From Date                                                       
C                   Eval      FD=CurDate - %days(%subdt(CurDate:*d)-1) - 
C                                          %months(1)              
 * To Date                                                         
C                   Eval      TD=CurDate - %days(%subdt(CurDate:*d))
C     FD            dsply 
C     TD            dsply   

     Posted by: XYZ   

  This is some sample code. 

     Posted by: jimmy octane - TimeStamp extract date time   

       *=======================================================================
      * INPUT PARAMETERS
      *   Description        Type  Size    How Used
      *   -----------        ----  ----    --------
      *
     d TimeStamp       s               z
     d TheDate         s               d
     d TheTime         s               t
      *
      *  Main Line
      *
     c                   eval      TimeStamp = %timeStamp()
     c                   eval      Thedate = %date(TimeStamp)
     c                   eval      Thetime = %time(TimeStamp)
     c
      *
     c                   eval      *INLR = *on 

     Posted by: Using SQL to change time in TimeStamp field   

 Question:
I have a timestamp field with the value of (1989-11-30-24.00.00.000000). 
Using SQL how can I change the time value from '24.00.00.000000' 
to '00.00.00.000000'? 

Answer:
update myfile
set mystamp = timestamp(date(mystamp),time('00.00.00'))
where hour(mystamp) = 24



 

     Posted by: missing bracket!   

 numDate = %int(%char(date : *eur0);  //  ddmmyyyy

should be 

numDate = %int(%char(date : *eur0));  //  ddmmyyyy
	    

     Posted by: mbrand - Returns Day Name   

       H Option(*NoDebugIO:*SrcStmt) DftActGrp(*No) ActGrp('agCHKDATE2')

      **----------------------------------------------------------------**
      * *Entry Plist                                                     *
      **----------------------------------------------------------------**
     D pEntryPList     pr                  ExtPgm('CHKDATE2')
     D  eDate                         6a
     D  eDayName                      9a

     D pEntryPList     pi
     D  eDate                         6a
     D  eDayName                      9a
      **----------------------------------------------------------------**
      * *Day Name Array
      **----------------------------------------------------------------**

     D DateNameArray   s              9a   Dim(7)
     D                                     CTData
     D                                     PerRcd(1)

     D wDateAlpha      s              6a

     D wDateStamp      s               d   Inz

      * Use January first, 2000 as the start date which fell on Saturday
     d wkDate          s              6a   Inz('010100')
     D dsBDate         s               d
     D dsXDate         s               d

     D wWeeks          s              5s 0
     D wDifference     s             10i 0

     D wRemainder      s              1s 0

      /free

         dsBDate = %Date(eDate:*mdy0);
         dsXdate = %Date(wkDate:*mdy0);

           Monitor;

              wDifference = %Diff(dsBDate: dsXDate: *D);
              wWeeks = %Div(wDifference:7);
              wRemainder = (%Rem(wDifference:7)+1);
              eDayName = DateNameArray(wRemainder);

           On-Error;

              eDayName = 'XXXXXXXXX';

           EndMon;

           *InLR = (*On);

      /end-free
**
Saturday
Sunday
Monday
Tuesday
Wednesday
Thrusday
Friday
 

     Posted by: suresh durairaj   

 //To calculate last 12 month's start and end date 
  including the current month

D todate          S               D   
D fromdate        S               D   
D index           S              2P 0 inz(1)
D FromDateAr      S               D   dim(12)
D ToDateAr        S               D   dim(12)

 /FREE
  //Get the current month's starting and ending date 
  ToDate   = %date();
  ToDate   = ToDate + %Months(1);
  ToDate   = Todate - %Days(%subdt(ToDate:*days));
  Fromdate = Todate - %days(%subdt(Todate:*days));
  Fromdate = Fromdate + %days(1);

  //Load the Arrays with start date and end date
  Dow (index < 13);
    ToDateAr(index) = Todate;
    FromDateAr(index) = Fromdate;
    Todate = Fromdate - %days(1);
    Fromdate = todate - %days(%subdt(Todate:*days));
    Fromdate = Fromdate + %days(1);
    index = index + 1;
  Enddo;

  index = 1;
 
  //Display the end date and start dates 
  Dow (index < 13);
    Dsply FromDateAr(index); 
    Dsply ToDateAr(index);
    index = index + 1;
  Enddo;
  
  *inlr = *on;
 /END-FREE    


Post your Date Source

(must enter name and example to post)



Your Name/Description:
Date Example:







About Code400.com | resume | Search | Site Map | Suggestions
© Copyright 2003-2008 Code400.com



Friday Mar 12, 2010 @ 7:48 AM