Dear friends

How to get a no of months & years of a given date range e.g.

dldate=date(2000,05,25)
now if i substract the dldate from current date ie.
x=date()-dldate
it will give result no of days

but i want no of months in a single statement.
if any function is available in VFP6 or any other way to get it.

Thanks

--
sanjib

Re: how to get the no of month of a given date range by Man-wai

Man-wai
Thu Mar 29 06:53:43 CDT 2007

> dldate=date(2000,05,25)
> now if i substract the dldate from current date ie.
> x=date()-dldate
> it will give result no of days

Is it the way your user wants? or is it:

function months
lparameter m.ldDate, m.ldCutDate
local m.lnCount
m.lnCount=0
do while m.ldDate <= m.ldCutDate
m.ldDate=gomonth(m.ldDate,1)
m.lnCount=m.lnCount+1
enddo
return m.lnCount

> but i want no of months in a single statement.
> if any function is available in VFP6 or any other way to get it.

If you write a user-defined function... :)

--
.~. Might, Courage, Vision, SINCERITY. http://www.linux-sxs.org
/ v \ Simplicity is Beauty! May the Force and Farce be with you!
/( _ )\ (Ubuntu 6.10) Linux 2.6.20.4
^ ^ 19:48:01 up 5 days 7:00 0 users load average: 1.09 1.03 1.00
news://news.3home.net news://news.hkpcug.org news://news.newsgroup.com.hk

Re: how to get the no of month of a given date range by Man-wai

Man-wai
Thu Mar 29 07:42:30 CDT 2007

> function months
> lparameter m.ldDate, m.ldCutDate
> local m.lnCount
> m.lnCount=0
> do while m.ldDate <= m.ldCutDate
> m.ldDate=gomonth(m.ldDate,1)
> m.lnCount=m.lnCount+1
> enddo
> return m.lnCount

There is a bug in the function, but you could figure it out. :)

--
.~. Might, Courage, Vision, SINCERITY. http://www.linux-sxs.org
/ v \ Simplicity is Beauty! May the Force and Farce be with you!
/( _ )\ (Ubuntu 6.10) Linux 2.6.20.4
^ ^ 20:41:01 up 5 days 7:53 0 users load average: 1.02 1.01 1.00
news://news.3home.net news://news.hkpcug.org news://news.newsgroup.com.hk

Re: how to get the no of month of a given date range by Tim

Tim
Thu Mar 29 08:01:11 CDT 2007

If the two dates are mdate and m2date try

12(year(mdate)-year(m2date))+(month(mdate)-month(m2date))


In article <OeShWjfcHHA.3632@TK2MSFTNGP02.phx.gbl>, Man-wai Chang
<toylet.toylet@gmail.com> writes
>> dldate=date(2000,05,25)
>> now if i substract the dldate from current date ie.
>> x=date()-dldate
>> it will give result no of days
>
>Is it the way your user wants? or is it:
>
>function months
>lparameter m.ldDate, m.ldCutDate
>local m.lnCount
>m.lnCount=0
>do while m.ldDate <= m.ldCutDate
> m.ldDate=gomonth(m.ldDate,1)
> m.lnCount=m.lnCount+1
>enddo
>return m.lnCount
>
>> but i want no of months in a single statement.
>> if any function is available in VFP6 or any other way to get it.
>
>If you write a user-defined function... :)
>

--
Tim Hobson

Re: how to get the no of month of a given date range by Man-wai

Man-wai
Thu Mar 29 08:33:55 CDT 2007

> 12(year(mdate)-year(m2date))+(month(mdate)-month(m2date))

thank you.

--
.~. Might, Courage, Vision, SINCERITY. http://www.linux-sxs.org
/ v \ Simplicity is Beauty! May the Force and Farce be with you!
/( _ )\ (Ubuntu 6.10) Linux 2.6.20.4
^ ^ 21:33:01 up 5 days 8:45 0 users load average: 1.00 1.00 1.00
news://news.3home.net news://news.hkpcug.org news://news.newsgroup.com.hk

Re: how to get the no of month of a given date range by Gene

Gene
Thu Mar 29 11:58:13 CDT 2007

Man-wai Chang <toylet.toylet@gmail.com> wrote:

>> function months
>> lparameter m.ldDate, m.ldCutDate
>> local m.lnCount
>> m.lnCount=0
>> do while m.ldDate <= m.ldCutDate
>> m.ldDate=gomonth(m.ldDate,1)
>> m.lnCount=m.lnCount+1
>> enddo
>> return m.lnCount
>
>There is a bug in the function, but you could figure it out. :)

Which one? I see two:

1) If lddate>ldcutdate, then the result is 0 regardless of how far
apart the dates are.

2) The number of days in the month can bite you. The function
returns 3 for 2007-01-31 and 2007-03-28. (Hint: What happens when
lddate={^2007.01.31} and it is incremented by one month? What happens
for the month after?)

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.

Re: how to get the no of month of a given date range by Man-wai

Man-wai
Thu Mar 29 22:19:01 CDT 2007

> 2) The number of days in the month can bite you. The function
> returns 3 for 2007-01-31 and 2007-03-28. (Hint: What happens when
> lddate={^2007.01.31} and it is incremented by one month? What happens
> for the month after?)

That's the bug I had in mind.. :)

--
iTech Consulting Services Limited
Expert of ePOS solutions
Website: http://www.itech.com.hk (IE only)
Tel: (852)2325 3883 Fax: (852)2325 8288

Re: how to get the no of month of a given date range by AtoutFox

AtoutFox
Fri Mar 30 10:37:09 CDT 2007

if you you want approximate divide the difference of the two dates by 30,44
then use INT of that if you want full months or round if your want the
nearest number of months even unfinished ones
then for years divide by 12 and for the left months MOD will do the trick

dldate=date(2000,05,25)
x=date()-dldate
date(2007,03,31) - date(2000,05,25) = 2501 days = 82,16 months = 82 months =
6 years and 10 months



"sanjib" <sanjibaich2005@example.com> a écrit dans le message de news:
A23A31B6-1C1D-44DD-A018-229CD8F3680F@microsoft.com...
> Dear friends
>
> How to get a no of months & years of a given date range e.g.
>
> dldate=date(2000,05,25)
> now if i substract the dldate from current date ie.
> x=date()-dldate
> it will give result no of days
>
> but i want no of months in a single statement.
> if any function is available in VFP6 or any other way to get it.
>
> Thanks
>
> --
> sanjib



Re: how to get the no of month of a given date range by imaginecorp

imaginecorp
Sat Mar 31 22:02:08 CDT 2007

Hello Sanjib;
Try this. create it as a procedure and send it the 2 dates:

Lparameters pstart, pend
Local nYears, nMonths, nDays, nTotalMonths,nYearsDiff
Store 0 To nYears, nMonths, nDays, nTotalMonths, nYearsDiff
pend = pend + 1
date1 = Min(pstart,pend)
date2 = Max(pstart,pend)
nYearsDiff =Year(date2) - Year(date1) - 1
nTotalMonths = Iif(nYearsDiff >= 1,nYearsDiff * 12 ,0)
Do While Gomonth(date1,nTotalMonths) <= date2
nTotalMonths = nTotalMonths + 1
Enddo
nTotalMonths = nTotalMonths-1
nYears = Floor(nTotalMonths/12)
nMonths = Mod(nTotalMonths,12)
nDays = date2 - Gomonth(date1,nTotalMonths)
? nYears
? nMonths
? nDays

--
Mohammed Ashruff
www.imaginecorp.com

"sanjib" <sanjibaich2005@example.com> wrote in message
news:A23A31B6-1C1D-44DD-A018-229CD8F3680F@microsoft.com...
> Dear friends
>
> How to get a no of months & years of a given date range e.g.
>
> dldate=date(2000,05,25)
> now if i substract the dldate from current date ie.
> x=date()-dldate
> it will give result no of days
>
> but i want no of months in a single statement.
> if any function is available in VFP6 or any other way to get it.
>
> Thanks
>
> --
> sanjib