SBP '''' GETDATE.SBP '''' November 28, 1994 '''' Written by Jared Oakes '''' Copyright (c) 1994, The Oakes Group '''' '''' GetDate V2.0 is a library of date related functions that I have written as a '''' tool for other programmers. I have uploaded this file as shareware, you can '''' analyze the functions as much as you like but if you use any function (whole '''' or in part) in your code please send $15 (US Dollars) to: '''' '''' Jared Oakes '''' P.O. Box 7473 '''' The Woodlands, TX 77387 '''' USA '''' '''' Once purchased the code can be used royalty free in as many applications as '''' you wish. If you have any ideas or suggestions you can reach me the address '''' above or send me a note to my CompuServe address 73021,2434. '''' '''' The purchase price will include an upgrade to GetDate V3.0 for SuperBase V3.0 '''' once it is completed. ' ************************************************************************************** ' * GetDate&%() - Displays a dialog box calendar allowing selection of a date. The ' * month and year of the displayed calendar can be scrolled forward ' * and backward as well as selected from a list. A reset button is ' * provided to allow the default date to be displayed in the main ' * calendar dialog box. A start date and an end date can be used to ' * limit the dates that can be selected. ' * ' * GDTitle$ - Title displayed on the main calendar dialog box. ' * GDDefault&% - The default date (in julian date format) that is initially ' * displayed when the fuction is first called. Also the date that ' * is displayed when the reset button is selected. ' * GDStart&% - The earliest date (in julian date format) the user will be ' * allowed to select. If GDStart&% = 0 then a start date will not be ' * used. ' * GDEnd&% - The latest date (in julian date format) the user will be allowed ' * to select. If GDEnd&% = 0 then an end date will not be used. ' * ' * Returns - A user selected date (in julian date format) or 0 if cancelled. ' * ' * Example - ? Date$(GetDate&%("Selecte Date",TODAY,TODAY-5,TODAY+5)) ' * ' * Note - GetDate&%() is dependant upon the functions GetMonth%%() and ' * GetYear%%() being available. ' ************************************************************************************** ÿÿmain() ÿÂÿ(GetDate&%("Select Desired Date",ÿQ,0,0)) ÿ’ÿÿ ÿÿGetDate&%(GDTitle$,GDDefault&%,GDStart&%,GDEnd&%) ÿÅÿÊ ÿ‹"mm/dd/yyyy" ÿ¡GDEnd&%ÿ0ÿp GDEnd&%ÿ999999999 ÿ’ÿ¡ CurrDate&%ÿGDDefault&% CurrMonth%%ÿÿ5(CurrDate&%) CurrYear%%ÿÿ6(CurrDate&%) sel%%ÿ1 ÿØsel%%ÿ0 CurrDate$ÿÿ(CurrMonth%%,"99")ÿ"/1/"ÿÿ(CurrYear%%,"9999") FirstDay%%ÿÿ?("SuMoTuWeThFrSa",ÿ+(ÿ2(CurrDate$),2))ÿ((ÿ?("SuMoTuWeThFrSa",ÿ+(ÿ2(CurrDate$),2))ÿ2)ÿ.5) ÿ‰ÿñ"calendar",0,0,173,112,GDTitle$,"System",10 ÿ|ÿñ"calendar",5,5,13,16,8,1,"Su" ÿ|ÿñ"calendar",5,21,13,16,8,1,"M" ÿ|ÿñ"calendar",5,37,13,16,8,1,"Tu" ÿ|ÿñ"calendar",5,53,13,16,8,1,"W" ÿ|ÿñ"calendar",5,69,13,16,8,1,"Th" ÿ|ÿñ"calendar",5,85,13,16,8,1,"F" ÿ|ÿñ"calendar",5,101,13,16,8,1,"Sa" ÿ|ÿñ"calendar",1,127,5,10,15,0,"<",57,1 ÿ|ÿñ"calendar",1,135,5,25,15,0,"Year",51,1 ÿ|ÿñ"calendar",1,158,5,10,15,0,">",58,1 ÿ|ÿñ"calendar",1,127,21,10,15,0,"<",55,1 ÿ|ÿñ"calendar",1,135,21,25,15,0,"Month",52,1 ÿ|ÿñ"calendar",1,158,21,10,15,0,">",56,0 ÿ|ÿñ"calendar",1,127,37,41,15,ÿ¡(ÿQÿ GDEnd&%,ÿ¡(ÿQÿGDStart&%,1,134217728),134217728),"Today",53,1 ÿ|ÿñ"calendar",1,127,53,41,15,0,"Reset",54,1 ÿ|ÿñ"calendar",1,127,69,41,15,0,"Cancel",0,0 CurrDate&%ÿÿ1(CurrDate$) ÿ›y%%ÿ0ÿq5 ÿ›x%%ÿ0ÿq6  ÿ¡y%%ÿ0ÿ x%%ÿ0ÿpx%%ÿFirstDay%%  d&%ÿ(CurrDate&%ÿ(7ÿy%%)ÿx%%ÿFirstDay%%)  ÿ¡ÿ3(d&%)ÿ ÿ3(d&%ÿ1)ÿp (ÿ|ÿñ"calendar",1,(16ÿx%%)ÿ8,(14ÿy%%)ÿ23,15,13,ÿ¡(d&%ÿ GDEnd&%,ÿ¡(d&%ÿGDStart&%,0,134217728),134217728),ÿH(ÿ(ÿ3(d&%),"99")),ÿ3(d&%),1  ÿ^ (ÿ|ÿñ"calendar",1,(16ÿx%%)ÿ8,(14ÿy%%)ÿ23,15,13,ÿ¡(d&%ÿ GDEnd&%,ÿ¡(d&%ÿGDStart&%,0,134217728),134217728),ÿH(ÿ(ÿ3(d&%),"99")),ÿ3(d&%),1 (ÿ|ÿñ"calendar",4,5,1,117,(14ÿy%%)ÿ37,0,ÿ4(CurrDate&%)ÿ" "ÿÿ(CurrYear%%,"9999") (y%%ÿ5:x%%ÿ6  ÿ’ÿ¡ ÿ±x%% ÿ±y%% ÿñ"calendar",sel%% ÿ¾ÿñ"calendar" ÿÉÿæsel%% ÿæ0  GetDate&%ÿ0 ÿæ51' ~~ Select Year  HoldYear%%ÿCurrYear%%  CurrYear%%ÿGetYear%%("Select Year",CurrYear%%)  ÿ¡CurrYear%%ÿ0ÿp (CurrYear%%ÿHoldYear%%  ÿ’ÿ¡ ÿæ52' ~~ Select Month  HoldMonth%%ÿCurrMonth%%  CurrMonth%%ÿGetMonth%%("Select Month",CurrMonth%%)  ÿ¡CurrMonth%%ÿ0ÿp (CurrMonth%%ÿHoldMonth%%  ÿ’ÿ¡ ÿæ53' ~~ Today  GetDate&%ÿÿQ  sel%%ÿ0 ÿæ54' ~~ Reset  CurrMonth%%ÿÿ5(GDDefault&%)  CurrYear%%ÿÿ6(GDDefault&%) ÿæ55' ~~ Previous Month  CurrMonth%%ÿ(CurrMonth%%ÿ1)ÿ12  ÿ¡CurrMonth%%ÿ0ÿp (CurrMonth%%ÿ12 (CurrYear%%ÿCurrYear%%ÿ1  ÿ’ÿ¡ ÿæ56' ~~ Next Month  CurrMonth%%ÿ(CurrMonth%%ÿ1)ÿ12  ÿ¡CurrMonth%%ÿ0ÿp (CurrMonth%%ÿ12  ÿ’ÿ¡  ÿ¡CurrMonth%%ÿ1ÿp (CurrYear%%ÿCurrYear%%ÿ1  ÿ’ÿ¡ ÿæ57' ~~ Previous Year  CurrYear%%ÿCurrYear%%ÿ1 ÿæ58' ~~ Next Year  CurrYear%%ÿCurrYear%%ÿ1 ÿæÿ^  GetDate&%ÿCurrDate&%ÿsel%%ÿ1  sel%%ÿ0 ÿ’ÿÉ ÿÙ ÿ¨ÿÊ ÿ’ÿÿ ' ************************************************************************************** ' * GetMonth%%() - Displays a dialog box with a button for each month of the year ' * ' * GMTitle$ - Title displayed on the month selection dialog box. ' * GMDefault%% - The number of the month button to be highlighted. ' * ' * Returns - The number of the month selected or 0 if cancelled. ' * ' * Example - ? GetMonth%%("Select Month",2) ' ************************************************************************************** ÿÿGetMonth%%(GMTitle$,GMDefault%%) HoldMonth%%ÿGMDefault%% ÿ‰ÿñ"months",0,0,154,85,GMTitle$,"System",10 ÿ›GMA%%ÿ0ÿq3 ÿ›GMB%%ÿ0ÿq2 GMC%%ÿ((GMA%%)ÿ3)ÿGMB%%ÿ1 ÿ|ÿñ"months",1,1ÿ((GMB%%)ÿ51),1ÿ((GMA%%)ÿ21),50,20,ÿ¡(GMC%%ÿGMDefault%%,1,0),ÿ4(1ÿ(32ÿ(GMC%%ÿ1))),(GMC%%ÿ1),1 ÿ±GMB%% ÿ±GMA%% ÿñ"months",GetMonth%% ÿ¾ÿñ"months" ÿ’ÿÿ ' ************************************************************************************** ' * GetYear%%() - Displays a dialog box allowing the selection of a year. ' * ' * GYTitle$ - Title displayed on the year selection dialog box. ' * GYDefault%% - The default year. ' * ' * Returns - The year selected or 0 if cancelled. ' * ' * Example - ? GetYear%%("Select Year",1994) ' ************************************************************************************** ÿÿGetYear%%(GYTitle$,GYDefault%%) ÿ×YearList$(40) ÿ×CurrYear$(0) CurrYear$(0)ÿÿ(GYDefault%%,"9999") sel%%ÿ2 ÿØsel%%ÿ1 ÿ›GYA%%ÿ0ÿq40 YearList$(GYA%%)ÿÿ(ÿ0(CurrYear$(0))ÿ20ÿGYA%%,"9999") ÿ±GYA%% ÿ‰ÿñ"years",0,0,92,121,GYTitle$,"System",10 ÿ|ÿñ"years",7,5,16,48,89,0,2,YearList$,CurrYear$(0),CurrYear$(0) ÿ|ÿñ"years",1,58,3,30,15,1,"OK",1,1 ÿ|ÿñ"years",1,58,19,30,15,0,"Cancel",0,0 ÿ|ÿñ"years",1,4,3,50,12,0,"Before "ÿYearList$(0),2,0 ÿ|ÿñ"years",1,4,105,50,12,0,"After "ÿYearList$(40),3,0 ÿñ"years",sel%% ÿ¾ÿñ"years" ÿÉÿæsel%% ÿæ1  GetYear%%ÿÿ0(CurrYear$(0)) ÿæ0  GetYear%%ÿ0  sel%%ÿ1 ÿæ2  CurrYear$(0)ÿYearList$(0) ÿæ3  CurrYear$(0)ÿYearList$(40) ÿ’ÿÉ ÿÙ ÿ’ÿÿ ' ************************************************************************************** ' * DayOfWeek%%()- Returns the day of the week number for a specific date. ' * ' * DOWDate&% - Date to be evaluated (julian date format). ' * ' * Returns - The number of the day of the week for the specified date. ' * ' * Example - ? DayOfWeek%%(TODAY) ' * ' * Note - This function assumes that Sunday if the first day of the week ' ************************************************************************************** ÿÿDayOfWeek%%(DOWDate&%) DayOfWeek%%ÿ(ÿ?("SuMoTuWeThFrSa",ÿ+(ÿ2(DOWDate&%),2))ÿ1)ÿ2 ÿ’ÿÿ ' ************************************************************************************** ' * AddWorkDay&%() - Adds the specified number of work days to the desired date. ' * ' * AWDStart&% - Date to add the work days to (julian date format). ' * AWDAdd&% - Number of work days to add. ' * ' * Returns - A date that is the number of work days later than the start ' * date (julian date format). ' * ' * Example - ? DATE$(AddWorkDay&%(TODAY,15)) ' * ' * Note - This function uses Saturday and Sunday as non-working days. ' * If days other than Saturday and Sunday need to be used in the ' * calculation than use the AddWorkDayUD&%() function. ' ************************************************************************************** ÿÿAddWorkDay&%(AWDStart&%,AWDAdd&%) AWDCount&%ÿ1 ÿØAWDCount&%ÿ AWDAdd&% DOW%%ÿ(ÿ?("SuMoTuWeThFrSa",ÿ+(ÿ2(AWDStart&%ÿAWDCount&%),2))ÿ1)ÿ2 AWDAdd&%ÿAWDAdd&%ÿÿ¡(DOW%%ÿ1,1,ÿ¡(DOW%%ÿ7,1,0)) AWDCount&%ÿAWDCount&%ÿ1 ÿÙ AddWorkDay&%ÿAWDStart&%ÿAWDAdd&% ÿ’ÿÿ ' ************************************************************************************** ' * AddWorkDayUD&%() - Adds the specified number of work days to the desired date ' * with user defined work days used in the calculation. ' * ' * AWDStart&% - Date to add the work days to (julian date format). ' * AWDAdd&% - Number of work days to add. ' * Su%% - 0 = Sunday is a work day, 1 = Sunday is not a work day ' * Mo%% - 0 = Monday is a work day, 1 = Monday is not a work day ' * Tu%% - 0 = Tuesday is a work day, 1 = Tuesday is not a work day ' * We%% - 0 = Wednesday is a work day, 1 = Wednesday is not a work day ' * Th%% - 0 = Thursday is a work day, 1 = Thursday is not a work day ' * Fr%% - 0 = Friday is a work day, 1 = Friday is not a work day ' * Sa%% - 0 = Saturday is a work day, 1 = Saturday is not a work day ' * ' * Returns - A date that is the number of work days later than the start ' * date (julian date format). ' * ' * Example - ? DATE$(AddWorkDayUD&%(TODAY,15,1,0,0,0,0,0,0)) ' * ' * Note - If Sunday and Monday are the only non-working days then it ' * would be easier to use the AddWorkDay&%() function. ' ************************************************************************************** ÿÿAddWorkDayUD&%(AWDStart&%,AWDAdd&%,Su%%,Mo%%,Tu%%,We%%,Th%%,Fr%%,Sa%%) ÿ¡Su%%ÿMo%%ÿTu%%ÿWe%%ÿTh%%ÿFr%%ÿSa%%ÿ 7ÿp AWDCount&%ÿ1 ÿØAWDCount&%ÿ AWDAdd&% DOW%%ÿ(ÿ?("SuMoTuWeThFrSa",ÿ+(ÿ2(AWDStart&%ÿAWDCount&%),2))ÿ1)ÿ2 AWDAdd&%ÿAWDAdd&%ÿÿ¡(Su%%ÿ DOW%%ÿ1,1,ÿ¡(Mo%%ÿ DOW%%ÿ2,1,ÿ¡(Tu%%ÿ DOW%%ÿ3,1,ÿ¡(We%%ÿ DOW%%ÿ4,1,ÿ¡(Th%%ÿ DOW%%ÿ5,1,ÿ¡(Fr%%ÿ DOW%%ÿ6,1,ÿ¡(Sa%%ÿ DOW%%ÿ7,1,0))))))) AWDCount&%ÿAWDCount&%ÿ1 ÿÙ ÿ’ÿ¡ AddWorkDayUD&%ÿAWDStart&%ÿAWDAdd&% ÿ’ÿÿ ' ************************************************************************************** ' * LandWorkDay&%() - Adds the specified number of days to a date and makes sure ' * the resulting day lands upon a valid work day with user ' * defined work days used in the calculation. ' * ' * LWDStart&% - Start date (julian date format). ' * LWDAdd%% - Number of days to add to the start date. ' * LWDBefore%% - 1 = If calculated date is a non-work day the first valid ' * working day before the calculated date will be returned. ' * 0 = If calculated date is a non-work day the first valid ' * working day after the calculated date will be returned. ' * ' * Returns - A valid working day (julian date format). ' * ' * Example - ? DATE$(LandWorkDay&%(TODAY,15,1)) ' * ' * Note - This function uses Saturday and Sunday as non-working days. ' * If days other than Saturday and Sunday need to be used in the ' * calculation than use the LandWorkDayUD&%() function. ' ************************************************************************************** ÿÿLandWorkDay&%(LWDStart&%,LWDAdd&%,LWDBefore%%) ÿÉÿæÿ2(LWDStart&%ÿLWDAdd&%) ÿæ"Saturday" ÿ¡LWDBefore%%ÿp  LandWorkDay&%ÿLWDStart&%ÿLWDAdd&%ÿ1 ÿ^  LandWorkDay&%ÿLWDStart&%ÿLWDAdd&%ÿ2 ÿ’ÿ¡ ÿæ"Sunday" ÿ¡LWDBefore%%ÿp  LandWorkDay&%ÿLWDStart&%ÿLWDAdd&%ÿ2 ÿ^  LandWorkDay&%ÿLWDStart&%ÿLWDAdd&%ÿ1 ÿ’ÿ¡ ÿæÿ^ LandWorkDay&%ÿLWDStart&%ÿLWDAdd&% ÿ’ÿÉ ÿ’ÿÿ ' ************************************************************************************** ' * LandWorkDayUD&%() - Adds the specified number of days to a date and makes sure ' * the resulting day lands upon a valid work day. ' * ' * LWDStart&% - Start date (julian date format). ' * LWDAdd%% - Number of days to add to the start date. ' * LWDBefore%% - 1 = If calculated date is a non-work day the first valid ' * working day before the calculated date will be returned. ' * 0 = If calculated date is a non-work day the first valid ' * working day after the calculated date will be returned. ' * Su%% - 0 = Sunday is a work day, 1 = Sunday is not a work day ' * Mo%% - 0 = Monday is a work day, 1 = Monday is not a work day ' * Tu%% - 0 = Tuesday is a work day, 1 = Tuesday is not a work day ' * We%% - 0 = Wednesday is a work day, 1 = Wednesday is not a work day ' * Th%% - 0 = Thursday is a work day, 1 = Thursday is not a work day ' * Fr%% - 0 = Friday is a work day, 1 = Friday is not a work day ' * Sa%% - 0 = Saturday is a work day, 1 = Saturday is not a work day ' * ' * Returns - A valid working day (julian date format). ' * ' * Example - ? DATE$(LandWorkDayUD&%(TODAY,15,1,1,0,0,0,0,0,0)) ' * ' * Note - If Sunday and Monday are the only non-working days then it ' * would be easier to use the LandWorkDay&%() function. ' ************************************************************************************** ÿÿLandWorkDayUD&%(LWDStart&%,LWDAdd&%,LWDBefore%%,Su%%,Mo%%,Tu%%,We%%,Th%%,Fr%%,Sa%%) LWDFound%%ÿ0 ÿØÿOLWDFound%% ÿÉÿæÿ2(LWDStart&%ÿLWDAdd&%) ÿæ"Sunday"  ÿ¡Su%%ÿp (ÿ¡LWDBefore%%ÿp 0LWDAdd&%ÿLWDAdd&%ÿ1 (ÿ^ 0LWDAdd&%ÿLWDAdd&%ÿ1 (ÿ’ÿ¡  ÿ^ (LWDFound%%ÿ1  ÿ’ÿ¡ ÿæ"Monday"  ÿ¡Mo%%ÿp (ÿ¡LWDBefore%%ÿp 0LWDAdd&%ÿLWDAdd&%ÿ1 (ÿ^ 0LWDAdd&%ÿLWDAdd&%ÿ1 (ÿ’ÿ¡  ÿ^ (LWDFound%%ÿ1  ÿ’ÿ¡ ÿæ"Tuesday"  ÿ¡Tu%%ÿp (ÿ¡LWDBefore%%ÿp 0LWDAdd&%ÿLWDAdd&%ÿ1 (ÿ^ 0LWDAdd&%ÿLWDAdd&%ÿ1 (ÿ’ÿ¡  ÿ^ (LWDFound%%ÿ1  ÿ’ÿ¡ ÿæ"Wednesday"  ÿ¡We%%ÿp (ÿ¡LWDBefore%%ÿp 0LWDAdd&%ÿLWDAdd&%ÿ1 (ÿ^ 0LWDAdd&%ÿLWDAdd&%ÿ1 (ÿ’ÿ¡  ÿ^ (LWDFound%%ÿ1  ÿ’ÿ¡ ÿæ"Thursday"  ÿ¡Th%%ÿp (ÿ¡LWDBefore%%ÿp 0LWDAdd&%ÿLWDAdd&%ÿ1 (ÿ^ 0LWDAdd&%ÿLWDAdd&%ÿ1 (ÿ’ÿ¡  ÿ^ (LWDFound%%ÿ1  ÿ’ÿ¡ ÿæ"Friday"  ÿ¡Fr%%ÿp (ÿ¡LWDBefore%%ÿp 0LWDAdd&%ÿLWDAdd&%ÿ1 (ÿ^ 0LWDAdd&%ÿLWDAdd&%ÿ1 (ÿ’ÿ¡  ÿ^ (LWDFound%%ÿ1  ÿ’ÿ¡ ÿæ"Saturday"  ÿ¡Sa%%ÿp (ÿ¡LWDBefore%%ÿp 0LWDAdd&%ÿLWDAdd&%ÿ1 (ÿ^ 0LWDAdd&%ÿLWDAdd&%ÿ1 (ÿ’ÿ¡  ÿ^ (LWDFound%%ÿ1  ÿ’ÿ¡ ÿ’ÿÉ ÿÙ LandWorkDayUD&%ÿLWDStart&%ÿLWDAdd&% ÿ’ÿÿ ' ************************************************************************************** ' * AddMonths&%() - Adds a specified number of months to a date ' * ' * AMDate&% - The date to add the months to. ' * AMAdd%% - The number of the months to add. ' * ' * Returns - A julian date of AMDate&% plus the number of months in AMAdd%%. ' * ' * Example - ? AddMonths&%(today,3) ' ************************************************************************************** ÿÿAddMonths&%(AMDate&%,AMAdd%%) ÿÅÿÊ ÿ‹"mm/dd/yyyy" AMMonth%%ÿÿ5(AMDate&%) AMYear%%ÿÿ6(AMDate&%) AMDay$ÿÿ(ÿ3(AMDate&%),"00") AMMonth$ÿÿ¡(ÿ((AMMonth%%ÿAMAdd%%)ÿ12,"00")ÿ"00","12",ÿ((AMMonth%%ÿAMAdd%%)ÿ12,"00")) AMYear$ÿÿ(AMYear%%ÿÿ((AMMonth%%ÿAMAdd%%)ÿ12),"9999") ÿÉÿæÿ0(AMMonth$) ÿæ4,6,9,11 ÿ¡AMDay$ÿ"30"ÿp  AMDay$ÿ"30" ÿ’ÿ¡ ÿæ2 ÿ¡AMDay$ÿ"28"ÿp  TmpYr%%ÿÿ0(AMYear$)  AMDay$ÿÿ(28ÿÿ¡(TmpYr%%ÿ4ÿ0ÿ (TmpYr%%ÿ100ÿ0ÿ TmpYr%%ÿ400ÿ0),1,0),"00") ÿ’ÿ¡ ÿ’ÿÉ AddMonths&%ÿÿ1(AMMonth$ÿ"/"ÿAMDay$ÿ"/"ÿAMYear$) ÿ¨ÿÊ ÿ’ÿÿ