Previous Topic Next topic Print topic


DAYS Function

Purpose

Returns a FIXED BINARY (31,0) value for the number of days corresponding to the date d. The value is in Lilian format.

Syntax

DAYS (d, p, w)

Parameters

d is a string expression representing a date. If not specified, DAYS uses the value returned by DATETIME(). The value for d must have a computational type and should have a character type. If not, the DAYS function converts d to character.

p is a supported date/time pattern. If not specified, DAYS uses the value YYYYMMDDHHMISS9999. Like the value for d, p must have a computational type and should have a character type. If not, the DAYS function converts p to character.

w is an integer expression value of the century window to be used for any two-digit year formats.

  • Any positive numeric value is treated as a year.
  • Negative or zero values are treated as an offset and subtracted from the current, system-supplied year.
  • If not specified, the value of w is the value specified in the -window compiler option.

Description

The DAYS built-in function returns either the number of days corresponding to a date/time pattern string, or the number of days for today's date.

See the help topic Date/Time Built-in Functions for more information about Lilian format and supported date/time patterns.

Examples

This example uses the DAYS function to return the number of days from the start of the Lilian calendar to a specified date.

dt: proc options(main);

   dcl wkdays (7) char (6) var static init ('Sun', 'Mon', 'Tue', 'Weds', 'Thurs', 'Fri', 'Sat');

   dcl (string, pattern)   char (80)  var ;

   dcl str char (80) var;

   dcl f float bin (52);
   dcl d fixed bin (31);

   d = 0;
   string  = '14.02.2014';
   pattern = 'DD.MM.YYYY';

   put skip;
   d= days(string, pattern, 0);
   put skip list ('On Feb 14, 2014, ' || trim(d) || ' days elapsed since the start of the Lilian calendar.');

   put skip;
   put skip list ('Feb 14, 2014 was on a ' || wkdays(weekday(d)));

   put skip;
   f= secs(string, pattern, 0);
   put skip list ('On Feb 14, 2014, ' || trim(f) || ' seconds elapsed since the start of the Lilian calendar.');

   put skip;
   put skip list ('Converting the number of days elapsed back to the original pattern: ');
   str = daystodate(d, pattern);
   put skip list (str);

   put skip;
   put skip list ('Converting the number of seconds elapsed back to the original pattern: ');
   str = secstodate(f, pattern);
   put skip list (str);

   put skip;
   put skip list ("Converting the original date/time stamp to 'YYYYMMDD' : ");
   str = repattern((str), 'YYYYMMDD', pattern, 1976);
   put skip list (str);

end;

The above code sample prints the following:

On Feb 14, 2014, 157543 days elapsed since the start of the Lilian calendar.

Feb 14, 2014 was on a Fri

On Feb 14, 2014, 1.361171520000000E+010 seconds elapsed since the start of the Lilian calendar.

Converting the number of days elapsed back to the original pattern:

14.02.2014

Converting the number of seconds elapsed back to the original pattern:

14.02.2014

Converting the original date/time stamp to 'YYYYMMDD' :

20140214

Restrictions

None.

Previous Topic Next topic Print topic