camste
17th August 2009, 16:22
Hi everyone,
I'm sort of a novice when it comes to Baan scripting, and now I have a problem when trying to calculate a date. I need to find the first of the month as a date, so that I can use it to compare to a date in a query. This is what I have tried:


extern domain tcdate curr.mois
long curr.day

curr.day = load.long(date$(1;2))
curr.mois = date.num() - curr.day + 1

The problem is that I always get 0 as the day number (curr.day), and when subtracting that from curr.mois, I always get a blank value. When I try to assign date$ to a string variable and show it in the report it always appears as blank. Is there some special setting which must be set so that I can be able to use this standard variable? Is there another way I can do this? Does Baan have any built in functions like Oracle's trunc for dates for instance?

100ahr01
17th August 2009, 18:02
function domain tcdate first.of.month(domain tcdate i.date)
{
|* Declaration of local variables:
long x.yearno
long x.monthno
long x.month_dayno
domain tcdate o.first.of.month

|* Parse the date into year, month, day of month:
num.to.date(i.date, x.yearno, x.monthno, x.month_dayno)

|* Using the year and the month, create a new date with the first day:
date.to.num(x.yearno, x.monthno, 1)

return( o.first.of.month )
}

|* To use the function:
|*
|
| new.date = first.of.month(old.date)

Of couse you can achieve the same result with much less code!

wiggum
18th August 2009, 14:17
Use lval() instead of load.long() and your code will work.