Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Exact Months & Days Calculation
Message
From
04/07/2002 06:01:44
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
04/07/2002 05:46:13
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00675277
Message ID:
00675280
Views:
11
>hi all,
>
>i need to compute the exact period in months & days between 2 date values. eg. date1 = 15 Jan, 2002 date2 = 25 Jun, 2002
>
>how can i achieve this.
>
>sincere thanks in advance.
LPARAMETERS tdDate1, tdDate2
IF parameters() < 1
    RETURN replicate('0',8)
ENDIF
local lnYears, lnMonths,lnDays, ldTemp
tdDate2 = IIF(empty(tdDate2),date(),tdDate2)
if tdDate2 < tdDate1
	ldTemp = tdDate1
	tdDate1 = tdDate2
	tdDate2 = ldTemp
endif
lnYears = year(tdDate2)-year(tdDate1)
IF gomonth(tdDate1,lnYears*12) > tdDate2
    lnYears = lnYears - 1
ENDIF
tdDate1 = gomonth(tdDate1,lnYears*12)
lnMonths = 0
DO while month(tdDate1) # month(tdDate2)
    tdDate1 = gomonth(tdDate1,1)
    lnMonths = lnMonths + 1
ENDDO
IF day(tdDate1) > day(tdDate2)
    lnMonths = lnMonths - 1
    tdDate1 = gomonth(tdDate1,-1)
ENDIF
lnDays = tdDate2 - tdDate1
RETURN trans(int(lnYears * 10^4 + lnMonths * 10^2 + lnDays),'@R 9999/99/99')
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform