PreviousNextIndex

DATE function

Converts a single character string, a set of month, day, and year values, an integer expression, a DATETIME expression, or a DATETIME-TZ expression into a DATE value.

If the DATE function cannot produce a valid date given the specified argument(s), it returns a run-time error.

Syntax

DATE ( month , day , year ) 

DATE ( string ) 

DATE ( integer-expression ) 

DATE ( datetime-expression ) 

month
day
year
string
integer-expression
datetime-expression
Examples

This procedure reads data from an input file that contains date information from another system stored as character strings without slashes or dashes between month, day, and year. It tries to convert these dates to ABL dates. Some formats cannot be successfully converted. For example:

r-date.p
/* r-date.p */ 
DEFINE VARIABLE cnum  AS CHARACTER NO-UNDO FORMAT "x(3)". 
DEFINE VARIABLE cdate AS CHARACTER NO-UNDO FORMAT "x(16)". 
DEFINE VARIABLE iday  AS INTEGER   NO-UNDO. 
DEFINE VARIABLE imon  AS INTEGER   NO-UNDO. 
DEFINE VARIABLE iyr   AS INTEGER   NO-UNDO. 
DEFINE VARIABLE ddate AS DATE      NO-UNDO. 
INPUT FROM VALUE(SEARCH("r-date.dat")). 
REPEAT: 
  SET cnum cdate. 
  ASSIGN 
    imon  = INTEGER(SUBSTR(cdate,1,2)) 
    iday  = INTEGER(SUBSTR(cdate,4,2)) 
    iyr   = INTEGER(SUBSTR(cdate,7,2)) 
    /* Works for years within 50 of 2000 */ 
    iyr   = iyr + (IF (iyr < 50) THEN 2000 ELSE 1900) 
    ddate = DATE(imon,iday,iyr). 
  DISPLAY ddate. 
END. 
INPUT CLOSE. 

The following example shows the DATE (string) syntax:

r-date2.p
/* r-date2.p */ 
DEFINE VARIABLE cnum  AS CHARACTER NO-UNDO FORMAT "x(3)". 
DEFINE VARIABLE cdate AS CHARACTER NO-UNDO FORMAT "x(16)". 
DEFINE VARIABLE ddate AS DATE      NO-UNDO FORMAT "99/99/9999". 
INPUT FROM VALUE(SEARCH("r-date.dat")). 
REPEAT: 
  SET cnum cdate. 
  ddate = DATE(cdate). 
  DISPLAY ddate. 
END. 
INPUT CLOSE. 

This example produces the following output. It produces no date for the first example since spaces are not a valid date separator:

cnum  cdate            ddate      
----  ---------------- ---------- 
 nyd  01 01 86          
 ad   11-28-52         11/28/1952 
 red  12/08/56         12/08/1956 
 nsm  10.01.01         10/01/2001 
 hrl  1/8/1994         10/08/1994 

See also

ADD-INTERVAL function, DATE-FORMAT attribute, DATETIME function, DATETIME-TZ function, DAY function, ETIME function, INTERVAL function, ISO-DATE function, MONTH function, MTIME function, NOW function, TIME function, TIMEZONE function, TODAY function, WEEKDAY function, YEAR function, YEAR-OFFSET attribute


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex