moonoobie
4th August 2009, 09:51
Hi All,
How do I get what is the date for past 6 months from today?
Example: Today is 4th August 2009.
I want to get the past 6 months date. It would be a date in February.
Example: I've a form that allow user to key in number of months. If user key in 3, meaning I will generate past 3 months data.
Now I need to get the 'date-from' and 'date-to' during data selection. "Date-to" would be today's date. What is the date-from?
Thanks in advance!
wiggum
4th August 2009, 11:25
long date.from
long months.before
long year, month, day
num.to.date(date.num(), year, month, day)
year = year - (months.before / 12)
month = month - (months.before \ 12)
if month < 1 then
month = month + 12
year = year - 1
endif
date.from = date.to.num(year, month, day) + 1
manish_patel
4th August 2009, 12:55
long date.from
year = year - (months.before \ 12)
month = month - (months.before / 12)
I think by mistake you interchange division and mod operator. It should be like
year = year - (months.before / 12)
month = month - (months.before \ 12)
manish_patel
4th August 2009, 13:37
At very high level; just subtract (3o*no of months entered by user) from current date.
date.f=date.t-(30*no of month)
To be more specific you can try below code.
extern domain tcmcs.long mnth |user to key in number of months
extern domain tcdate date.f
extern domain tcdate date.t
domain tcmcs.long retval, year, month, day, tmp.month
date.t=date.num()
retval = num.to.date(date.t, year, month, day)
if month=mnth then
date.f=date.to.num(year-1,12,day)
else
if month-mnth<0 then
date.f = date.to.num(year-(mnths/12),abs(12+month-mnth),day)
else
date.f = date.to.num(year,month-mnth,day)
endif
endif
Please note that I have not tested this piece of code as now days I don’t have Baan access. It is just sample.
wiggum
5th August 2009, 10:37
I think by mistake you interchange division and mod operator. It should be like
year = year - (months.before / 12)
month = month - (months.before \ 12)
You're right, thanks. I've changed it.
wiggum
5th August 2009, 10:40
At very high level; just subtract (3o*no of months entered by user) from current date.
date.f=date.t-(30*no of month)
In this way you will get only an approximated value.