home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 463.lha / Date_routines / datename.c < prev    next >
Text File  |  1991-01-04  |  955b  |  38 lines

  1. /*****
  2.                               datename()
  3.  
  4.       This function returns the day of the week for a date. It is based
  5.    on Zeller's Congruence.
  6.  
  7.    Argument list:    int month      the month
  8.                      int day        the day
  9.                      int year       the year
  10.  
  11.    Return value:     char *         a pointer to the day of the week
  12.  
  13. *****/
  14.  
  15. char *datename(int day, int month, int year)
  16. {
  17.    static char *days[] = {"Sun.", "Mon.", "Tues", "Wed.",
  18.                           "Thur", "Fri.", "Sat.", "Sun."};
  19.  
  20.    int index;
  21.  
  22.    if (year < 100)         /* If century is missing         */
  23.       year += 1900;
  24.  
  25.    if (month > 2) {        /* Everything is from February   */
  26.       month -= 2;
  27.    } else {
  28.       month += 10;
  29.       year--;
  30.    }
  31.  
  32.    index = ((13 * month - 1) / 5) + day + (year % 100) + ( (year % 100) / 4)
  33.            + ((year / 100) / 4) - 2 * (year / 100) + 77;
  34.    index = index - 7 * (index / 7);
  35.  
  36.    return days[index];
  37. }
  38.