Saturday, March 26, 2016

@CalcMgrDateDiff and @CalcMgrGetDatePart

@CalcMgrDateDiff:

Syntax:

@CalcMgrDateDiff(fromDate, toDate, date_part)

date_part options:

  • "day"
  • "month"
  • "week"
  • "year"

Example(s):

VAR V_Start = 20160701;
VAR V_End = 20170630;
VAR V_Diff = 0;

V_Diff = @CalcMgrDateDiff(V_Start, V_End, "day");


Returns 364

V_Diff = @CalcMgrDateDiff(V_Start, V_End, "month");

Returns 11

V_Diff = @CalcMgrDateDiff(V_Start, V_End, "week");

Returns 52

V_Diff = @CalcMgrDateDiff(V_Start, V_End, @NAME("year"));

Returns 1

Note that when there exists dimension "Year" you may need to put the date_part inside "@NAME" as you see in the last example.




@CalcMgrGetDatePart:

Syntax:


@CalcMgrGetDatePart(date,date_part_ex)

date_part options:

  • "dayofmonth"
  • "dayofyear"
  • "month"
  • "weekofmonth"
  • "weekofyear"
  • "year

Example(s):

VAR V_Start = 20160701;
VAR V_Num = 0;

V_Num = @CalcMgrGetDatePart (V_Start, @NAME("year"));

 

Returns 2016

V_Num = @CalcMgrGetDatePart (V_Start, "dayofmonth");

Returns 1

"BegBalance" = @CalcMgrGetDatePart (V_Start, "dayofyear");

Returns 183

V_Num = @CalcMgrGetDatePart (V_Start, "month");

Returns 7

V_Num = @CalcMgrGetDatePart (V_Start, "weekofmonth");

Returns 1

V_Num = @CalcMgrGetDatePart (V_Start, "weekofyear");

Returns 27

2 comments:

  1. Thanks a lot Viren, it was really helpful , i was struggling from past few hours to get correct output, thanks a lot :)

    ReplyDelete
  2. Thanks alot, How ever i wanted to know where we find this info date_part options:
    "day"
    "month"
    "week"
    "year
    Is it in technical guide?

    ReplyDelete