home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / pcmag / vol10n17.zip / DATES2.PRG < prev    next >
Text File  |  1991-09-10  |  2KB  |  58 lines

  1. ***********************************************************************
  2. * DATES2.PRG
  3. * Demonstrates STOD and EOM functions for Clipper
  4. ***********************************************************************
  5. CLEAR SCREEN
  6. ? "Enter No Date to Quit ..."
  7. ?
  8. DO WHILE .T.
  9.    ACCEPT "Date > " TO mdate         && Get date
  10.    IF EMPTY(mdate)                   && Nothing means quit
  11.       RETURN
  12.    ENDIF
  13.  
  14.    mdate=CTOD(mdate)                 && Convert to date type
  15.    IF EMPTY(mdate)                   && If conversion failed
  16.       ? "Bad Date!"                  && Date is not valid
  17.       LOOP                           && Try another
  18.    ENDIF
  19.  
  20.    mdate = EOM(mdate)                && Get last date of month
  21.    ? "Last Date of Month:",mdate
  22.    ? "Number of Days in Month:",DAY(mdate)
  23. ENDDO
  24.  
  25. ***********************************************************************
  26. * Function STOD - String to date conversion (reverse of DTOS())
  27. *
  28. * Usage: d = STOD(dstr)
  29. *
  30. * dstr = A character string that holds a date in DTOS format: YYYYMMDD
  31. *        (Clipper's DTOS() function creates such a string)
  32. *
  33. * Returns d, which is dstr converted to a date value
  34. *
  35. * This is the complement to Clipper's DTOS() Function.
  36. ***********************************************************************
  37. FUNCTION stod
  38. PARAMETERS dstr
  39. RETURN CTOD(SUBSTR(dstr,5,2)+"/"+SUBSTR(dstr,7,2)+"/"+LEFT(dstr,4))
  40.  
  41. ***********************************************************************
  42. * Function EOM - Return the last date of the month
  43. *
  44. * Usage: d = EOM(mdate)
  45. *        mdate = Any valid date
  46. *
  47. * Returns d, a date variable containing the last valid date of the
  48. * month
  49. ***********************************************************************
  50. FUNCTION eom
  51. PARAMETERS pdate
  52. pdate = LEFT(DTOS(pdate),6) + "31"      && Start with the 31st
  53. DO WHILE EMPTY(STOD(pdate))             && If not valid, back up one
  54.    pdate = LEFT(pdate,6) + STR(VAL(RIGHT(pdate,2))-1,2)
  55. ENDDO
  56. RETURN STOD(pdate)                      && Return a date variable
  57.  
  58.