Page 1 of 1

function to get the date of the next monday.

Posted: Tue May 23, 2006 2:24 pm
by petburn
hello everybody,

i'm a new Datastage Developers.

i have a problem.

i explain myself :

i have to integrate one file into a data base.

the file is like it.

article;Qty1;Qty2;Qty3...Qt60

ex :
00001;1;2;3;4....60

the table in the data base is like this.

article - ref_Date - prevision_date - Qty

00001 - 20060523 - 20060529 - 1
00001 - 20060523 - 20060605 - 2
...


ref_Date is sysdate (i do not have any problem with tis)

the prevision_date is the next 60 monday. (one for each column in the file.)


so, my problem is.

how to get the date of the next monday. (the others will be next monday + 7 days...)

i wish you understand my problem.

thanks for your attention.

PS : sorry for my poor english, but i'm french and i do not speak english.

bye.

jerome

Posted: Tue May 23, 2006 2:34 pm
by ray.wurlod
The trick you need is to realize that the internal format of dates in server jobs is an integer. If you divide by 7 and take the remainder (the Mod() function), then the result is 0 for Sunday, 1 for Monday, through to 6 for Saturday.

So you take the date (current date is available as system variable @DATE or the Date() function) and do this arithmetic. Add sufficient days to it to get the date of next Monday.

Code: Select all

@DATE + (7 - Mod(@DATE,7) + 1 - ((Mod(@DATE,7) <= 1) * 7)
Each 1 in the expression represents Monday.

The result is in internal format; use Oconv() or one of the SDK Transforms to generate whatever external date format you require.

Posted: Tue May 23, 2006 2:51 pm
by petburn
thanks, i'll test it tomorow.

bye.