Chinaunix首页 | 论坛 | 博客
  • 博客访问: 31252
  • 博文数量: 9
  • 博客积分: 75
  • 博客等级: 民兵
  • 技术积分: 70
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-09 23:08
个人简介

好好工作,好好生活!

文章分类
文章存档

2013年(9)

分类: LINUX

2013-05-05 23:54:55

RPGLE提供了许多有关日期数据格式的用法,下面对这些日期的用法进行了一下汇总。 
1.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

2.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 ISOdate         S               D
     D USAdate         S               D   DatFmt(*USA)
     D XMASDate       S               D   Inz(D'2003-12-25')
      
  
  
  
3.Various types of Date data format   
      
*-----------------------------------------------------------
      * 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
      *
      *
      *----------------------------------------------------------

      

4.Use dates in RPGLE
     First get current date in ISO date format
     (without DATFMT or DATEDT keyword in control specification)

     
C                   Eval      ISOdate = %Date()

 
 
       Then,move this date to a decimal 8,0 field
       the date is now in format  20030926
     
  C                   Move      ISODate       Decimal8        8 0

 
 
 
     
      Now   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
	 




 yoyoage 回复于:2004-01-31 09:53:03

另外,日期格式之间可以相互转换
/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);         



 andrewleading_h 回复于:2004-01-31 10:08:01

不错,有机会试试看!帮忙顶一下!


 huim 回复于:2004-01-31 20:44:50

好贴


 红像 回复于:2004-02-02 09:15:03

Great~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


 yj2yq 回复于:2004-02-02 16:27:01

精彩!


 yoyoage 回复于:2004-02-02 19:58:17

另外还补充一下SQLRPGLE中的日期函数用法:
SQLRPGLE中,有下面这些可用的日期函数:
DATE 
DAY 
DAYS 
DAYOFMONTH 
DAYOFWEEK 
DAYOFWEEK_ISO 
DAYOFYEAR 

例如: 

SELECT Item, Date(Days(SUBSTR(CHAR(MFDATE),1,4)||'-'|| 
SUBSTR(CHAR(MFDATE),5,2)|| '-'|| 
SUBSTR(CHAR(MFDATE),7,2)) + EXPIRE) 
FROM ITEMMASTER 

MFDATE是YYYYMMDD格式的数据,存放生产日期
EXPIRE存放产品的生命周期,用天数表示。

DAYS函数可用于数字或者字符型,按照YYYY-MM-DD的格式计算天数。


 JaguarCool 回复于:2005-11-09 09:43:25

Eval      WorkISO  = ISODate + %Months(1)
     C                   Eval      Date_String =
     C                              %Trim(MonthNames(LogMonth))
     C                              + %trim('@') + %Trim(LogDay)
     C                              + %trim(',@') + %Char(LogYear)
(和)是什么时候意思啊?

我想是不是这个意思了:
Eval      WorkISO  = ISODate + %Months(1)
     C                   Eval      Date_String =
     C                              %Trim(MonthNames(LogMonth))
     C                              + %trim('@') + %Trim(LogDay)
     C                              + %trim(',@') + %Char(LogYear)

[ 本帖最后由 JaguarCool 于 2005-11-9 09:51 编辑 ]
阅读(2477) | 评论(0) | 转发(0) |
0

上一篇:把MSGF变成SPLF 把SPLF变成MEMBER(源文件)

下一篇:没有了

给主人留下些什么吧!~~