Kbase 6388: Programming with DATES
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  21/08/1998 |
|
Programming with DATES
910702-ANA01
INTRODUCTION:
=============
This Product Services Technical Support Knowledgebase entry contains
programming hints for using "dates".
WHY YOU NEED TO DO THIS:
========================
You might need special "date" values for which PROGRESS doesn't provide
ready-to-use functions. For example, you may want functions to
determine whether a given year is a leap year or not, the number of
remaining days in a year for a given date, and so on.
PROCEDURAL APPROACH:
===================
You can use the following functions in programs. You just
assign the derived date value to a variable or display the value.
However, in the description below every function is
designed as an include file, to make the usage more flexible.
LEAP YEAR
---------
Use this procedure to determine if a year is a leap year.
/* leap.i
*
* Takes an integer value representing a year (i.e. 1988) as argument.
* Returns a logical value, depending on whether the year is a leap
* year or not.
*
* Example: if {leap.i 1988} then message "1988 is a leap year".
*/
date(3, 1, {1}) - date(2, 28, {1}) > 1
REMAINING DAYS IN A YEAR
------------------------
Use this procedure to find the number of days left in a year.
/* daysleft.i
*
* Takes a date value as an argument.
* Returns an integer value indicating the number of remaining days in
* the year of the given date.
*
* Example: display "There are" {daysleft.i today} "more days in this
* year".
*/
date(12, 31, year({1}) - {1}
DAY OF THE YEAR
---------------
Use this procedure to find what day of the year it is.
/* daysover.i
*
* Takes a date value as argument.
* Returns an integer value indicating the number of the day in the year
* of the given date.
*
* Example: display "This is day number" {daysover.i today} "in this
* year".
*/
{1} - date(1, 1, year({1})) + 1
CALENDAR WEEK
-------------
Use this procedure to find the week of the year.
/* calweek.i
*
* Takes a date value as argument.
* Returns an integer indicating the calendar week of the given year.
*
*
* Example: display "Let's meet next week, i.e. CW" {calweek.i "today
* + 7"}.
*/
int(trunc(
(d - date(1,1,year({1})) + weekday(date(1,1,year({1})) - 1) / 7,
0)) + 1
ONLINE PROCEDURES OR UTILITIES:
===============================
None
REFERENCE TO WRITTEN DOCUMENTATION:
===================================
PROGRESS Language Reference: Functions, DATE, YEAR, WEEKDAY, INTEGER,
Progress Software Technical Support Note # 6388