Thanks. Completed.
The program will calculate the number of days between any two dates in history, then calculate the number of minutes between two times on those dates and output the two values.
Rem Project: Time Difference
Rem Created: Sunday, August 05, 2012
Rem ***** Main Source File *****
Define_TimeDiff_Vars()
Main_Code()
end
function Define_TimeDiff_Vars()
global g_ENGINE_DateDiff_TotalDays as integer
global g_ENGINE_TimeDiff_TotalMins as integer
global g_Date_Start$ as string : g_Date_Start$ = "26/06/1103"
global g_Time_Start$ as string : g_Time_Start$ = "08:00:00"
global g_Date_End$ as string : g_Date_End$ = "05/08/2012"
global g_Time_End$ as string : g_Time_End$ = "03:54:00"
endfunction
function Main_Code()
do
cls
lib_Get_TIME_DIFFERENCE(g_Time_Start$, g_Time_End$)
print
print " Time Difference Calculator"
print
print " Start Date : " + g_Date_Start$
print " End Date : " + g_Date_End$
print
print " Start Time : " + g_Time_Start$
print " End Date : " + g_Time_End$
print
print " Date Difference (days) : " + str$(g_ENGINE_DateDiff_TotalDays)
print " Time Difference (mins) : " + str$(g_ENGINE_TimeDiff_TotalMins)
loop
endfunction
function lib_CONVERT_DATE_US_to_UK_Format(r_ConvertDate$)
local l_DOut$ as string
l_DOut$ = right$(left$(r_ConvertDate$, 5), 2) + "/" + left$(r_ConvertDate$, 2) + "/" + right$(r_ConvertDate$, 2)
endfunction l_DOut$
function lib_Get_TIME_DIFFERENCE(r_Start_Time$ as string, r_End_Time$ as string)
local l_Start_Hr as integer
local l_Start_Min as integer
local l_Start_Sec# as float
local l_End_Hr as integer
local l_End_Min as integer
local l_End_Sec as integer
local l_Start_TotalMins# as float
local l_End_TotalMins# as float
l_Start_Hr = val(first token$(r_Start_Time$,":"))
l_Start_Min = val(next token$(":"))
l_Start_Sec# = val(next token$(""))
l_End_Hr = val(first token$(r_End_Time$,":"))
l_End_Min = val(next token$(":"))
l_End_Sec = val(next token$(""))
`First get the date difference in number of days
lib_Get_DATE_DIFFERENCE(g_Date_Start$, g_Date_End$)
`Case 1: If DayDifference=0 then all the minutes are on the same day and just subtract the times
`Case 2: If DayDifference=1 then calc from 00:00:00 to the end time + start_time to 23:59:59
`Case 3: If DayDifference>1 then calc from 00:00:00 to the end time + start_time to 23:59:59
` plus (DayDifference-1*1440) - 1440=minutes per day.
`Case 1
if g_ENGINE_DateDiff_TotalDays = 0
l_TmpFlt1# = ((l_Start_Hr * 60) + l_Start_Min + (l_Start_Sec# / 60.0))
l_TmpFlt2# = ((l_End_Hr * 60) + l_End_Min + (l_End_Sec / 60.0))
g_ENGINE_TimeDiff_TotalMins = l_TmpFlt2# - l_TmpFlt1#
endif
`Case 2
if g_ENGINE_DateDiff_TotalDays = 1
`Minutes Yesterday
l_TmpFlt1# = 1440 - ((l_Start_Hr * 60) + l_Start_Min + (l_Start_Sec# / 60.0))
`Minutes Today
l_TmpFlt2# = ((l_End_Hr * 60) + l_End_Min + (l_End_Sec / 60.0))
g_ENGINE_TimeDiff_TotalMins = l_TmpFlt1# + l_TmpFlt2#
endif
`Case 3
if g_ENGINE_DateDiff_TotalDays > 1
`Minutes Yesterday
l_TmpFlt1# = 1440 - ((l_Start_Hr * 60) + l_Start_Min + (l_Start_Sec# / 60.0))
`Minutes Today
l_TmpFlt2# = ((l_End_Hr * 60) + l_End_Min + (l_End_Sec / 60.0))
g_ENGINE_TimeDiff_TotalMins = l_TmpFlt1# + l_TmpFlt2# + ((g_ENGINE_DateDiff_TotalDays-1)*1440)
endif
endfunction
function lib_Get_DATE_DIFFERENCE(r_StartDate$ as string, r_EndDate$ as string)
`NOTE: Requires date in the format DD/MM/YYYY, if not use lib_CONVERT_DATE_US_to_UK_Format(r_ConvertDate$)
local l_Start_Day as integer : l_Start_Day = val(first token$(r_StartDate$,"/"))
local l_Start_Month as integer : l_Start_Month = val(next token$("/"))
local l_Start_Year as integer : l_Start_Year = val(next token$(""))
local l_End_Day as integer : l_End_Day = val(first token$(r_EndDate$,"/"))
local l_End_Month as integer : l_End_Month = val(next token$("/"))
local l_End_Year as integer : l_End_Year = val(next token$(""))
`Consider Jan+Feb as month 13 and 14
if l_Start_Month = 1 or l_Start_Month = 2
inc l_Start_Month, 12
dec l_Start_Year, 1
endif
if l_End_Month = 1 or l_End_Month = 2
inc l_End_Month, 12
dec l_End_Year, 1
endif
l_DayNum_Start = int(365*l_Start_Year) + int(l_Start_Year/4) - int(l_Start_Year/100) + int(l_Start_Year/400) + l_Start_Day + int((153*l_Start_Month+8)/5)
l_DayNum_End = int(365*l_End_Year) + int(l_End_Year/4) - int(l_End_Year/100) + int(l_End_Year/400) + l_End_Day + int((153*l_End_Month+8)/5)
g_ENGINE_DateDiff_TotalDays = l_DayNum_End - l_DayNum_Start
endfunction