how to use a date field?

hi,
please, what’s the point in using fields (variables) with format “(d)”, date?
what do I get and what do I lose?
thanks a lot.

Since D-format fields are represented in an internal format, you can do arithmetic with them. On the down side, the date values are proprietary, so you need to format them into alpha fields before you pass them to an application built with another language. On the up side, you can be very creative with the output format.

DEFINE DATA LOCAL  
1 #DATE (D)  
1 #EOY (D)    INIT <D'12/31/2008">  
1 #DAYS (N3)  INIT <10>  
1 #DATE-A (A10)  
1 #ALPHA (A31)  
END-DEFINE  
*  
ASSIGN #DATE = *DATX + #DAYS /* future date  
WRITE '=' *DATX  
    / '=' #DAYS  
    / '=' #DATE  
*  
ASSIGN #DAYS = #EOY - #DATE  /* elapsed days  
WRITE  
    / '=' #EOY  
    / '=' #DATE  
    / '=' #DAYS  
*  
MOVE EDITED #DATE (EM=MM/DD/YYYY)            TO #DATE-A    /* USA format  
MOVE EDITED #DATE (EM=N(10),^L(10)^ZD,^YYYY) TO #ALPHA     /* text  
WRITE  
   // '=' #DATE-A  
    / '=' #ALPHA  
END

In the example above, the date literal should be surrounded with apostrophes. To stop the Forum from truncating the value, I surrounded it with mismatched apostrophe/double-quote.

thanks a lot indeed!

A big advantage is, that you don’t have to think about leap years etc. One “disadvantage” of the Date-Format is, that you’re not able to represent dates before 1582 (= Start of Gregorian Calendar). But maybe this is very specific, e.g. if you want to store Birthdates of historical Persons or so …