Thursday, May 14, 2015

DATE function

DATE function

Syntax:

DATE ( expression [ , format-code ] )



Official description:
The DATE function formats the expression as a date according to the string given as format-code. If the format-code is omitted, the date format set in the operating system is used.

Parameters:
expression
can be numeric or alphanumeric. 
Typically alphanumeric representing a date. 
If numeric it also represents a date but as an offset from day 0 (zero) in QVW's date arithmetic 

Numeric value for expression
Date that they numeric value represents in YYYY-MM-DD format 

 0
1899-12-30

 1
1899-12-31

 1000000
4637-11-26 

 -1
1899-12-29




Outstanding questions:
Q. If the format-code is omitted, the date format set in the operating system is used.Do other SET system variables impact this?


Error situations:
DATE function returns NULL if it cant resolve the format to the ‘number’ supplied


Example : The format of the date supplied (1st parameter) does not match the format-code (2nd parameter) 
LET x=DATE ('01-01-2015', 'YYYY-MM-DD') ;

IF  ISNULL (x) THEN ;
    
let x='NULL' ;

end if ;

TRACE x=[$(x)] ;
Gives
x=[NULL] 

But it will happily accept unusual dates i.e. expression (1st parameter) with a value of zero:
 LET x=DATE (0, 'YYYY-MM-DD') ;

IF  ISNULL (x) THEN ;
    
let x='NULL' ;

end if ;

TRACE x=[$(x)] ;
Gives


x=[1899-12-30]