Focal Point
calculation date

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/5421067331

July 23, 2003, 02:10 PM
<mbribeche>
calculation date
Like Julian date for the number of current day, I could calculate the number of the current week. Somedoby can help me !

Roll Eyes
July 23, 2003, 04:55 PM
jimster06
Look at WebFOCUS' various date functions. Julian date, week number, etc are available.
July 23, 2003, 05:56 PM
jimster06
Another word or two:
There is date conversion function JULDATE that will convert YYMD or YMD format dates to YYYYJUL or YYJUL.
Another function, JULIAN, will extract the number of days from January 1 in the variable DATE and return an integer value.
The calculation of week number, a variable often used in retailing, takes a couple of steps. First, the Julian value of week 0 must be known; this probably varies by calendar year. Next, find the julian value of the current DATE. Subtract first from the second and divide the result by 7 to get the number of weeks from week 0. If you cross a year boundary, another step or two would be necessary.
November 17, 2003, 05:09 PM
susannah
Jimster06, WEEK number isn't available as a focus function. Whats available is /W, which is the day of the week, 1-7 (or is it 0-6, whatever );
Week number is a very important field in Retail, and we calculate it depending on the way of the week that "OUR" week begins. Different for Different retailers.
So, Week Number is a calculation, using
1) the Smart Date for Jan 1 of the current year,
2) figuring out what day of the week that is.
3) adjusting that smart date value either back a partial week or forward, depending on how we retailers count that partial week at the begining of a year.
4) taking today's smart date, figuring out what day of the week it is, adjusting to the beginning of our "week"
5) taking the difference between the two adjusted smart dates and dividing by 7.
That's how we do it.
It would, however, be great if ARt would write a UserWrittenSubRoutine to calculate week number, with those aguments. How about asking him for all of us out here in retail land.
November 17, 2003, 08:56 PM
Mikel
The week number can be extracted from a date/time field by using HPART function.
(Available since WF43 and FOCUS 7.1, I think).

See the HPART available Doc.

Regards,
Mikel
November 18, 2003, 11:25 AM
jimster06
My bad. I should have referred to WEEKFIRST, HPART, and HNAME. But I do concur with Susannah's suggestion for a more robust week number calculation based my experience with an Arkansas-based retailer.
November 19, 2003, 07:39 AM
Tewy
This is a piece of code I have recently written to calculate week numbers, since we're undergoing a major project where I currently work to change all the manufacturing systems from a Sunday-Saturday week to a Monday-Sunday week. Doesn't sound like such a big deal, except the first option gives us a week 53 this year (this was the original week numbering for this year) and now they want to change so there's only 52 weeks this year.


DEFINE FILE filename
DATE1/YYMD=fieldname;
DATE3/I8YYMD=DATE1;
DATE4/I8=DATE3;
WEEKDAY/A8 = DOWK(DATE4,WEEKDAY);
WED_DOWK/I1=DECODE WEEKDAY('MON' 2 'TUE' 3 'WED' 4 'THU' 5 'FRI' 6
'SAT' 7 'SUN' 1);
WED_DATE/YYMD=(DATE1 + 4)-WED_DOWK;
WED_DATE1/I8YYMD=WED_DATE;
WED_DATE2/I8=WED_DATE1;
WED_JULIAN_DATE/I5 = JULDAT(WED_DATE1, WED_JULIAN_DATE);
WED_JULIAN1/A5=EDIT(WED_JULIAN_DATE);
WED_JULIAN2/A3=EDIT(WED_JULIAN1, '$$999');
WED_JULIAN/I3=EDIT(WED_JULIAN2);
SUN_WEEK1/D7.2=WED_JULIAN/7;
SUN_WEEK2/A8=FTOA(SUN_WEEK1, '(D7.2)', SUN_WEEK2);
SUN_WEEK3/A2=EDIT(SUN_WEEK2, '$$$$$$99');
SUN_WEEKA/I3=WED_JULIAN/7;
SUN_WEEK/I3=IF SUN_WEEK3 EQ '00' THEN SUN_WEEKA ELSE SUN_WEEKA + 1;
THU_DOWK/I1=DECODE WEEKDAY('MON' 1 'TUE' 2 'WED' 3 'THU' 4 'FRI' 5
'SAT' 6 'SUN' 7);
THU_DATE/YYMD=(DATE1 + 4)-THU_DOWK;
THU_DATE1/I8YYMD=THU_DATE;
THU_DATE2/I8=THU_DATE1;
THU_JULIAN_DATE/I5 = JULDAT(THU_DATE1, THU_JULIAN_DATE);
THU_JULIAN1/A5=EDIT(THU_JULIAN_DATE);
THU_JULIAN2/A3=EDIT(THU_JULIAN1, '$$999');
THU_JULIAN/I3=EDIT(THU_JULIAN2);
THU_WEEK1/D7.2=THU_JULIAN/7;
THU_WEEK2/A8=FTOA(THU_WEEK1, '(D7.2)', THU_WEEK2);
THU_WEEK3/A2=EDIT(THU_WEEK2, '$$$$$$99');
THU_WEEKA/I3=THU_JULIAN/7;
MON_WEEK/I3=IF THU_WEEK3 EQ '00' THEN THU_WEEKA ELSE THU_WEEKA + 1;#
END
December 11, 2003, 12:54 AM
susannah
That Hpart thing is cool.
Tewy, here's a way you can really shorten your code: To get the week number for today...
1.take the difference between today and the first day of the year (using smart dates)
2. divide that difference by 7
(gives you the current week number)
3.using the MOD function get the remainder from that division, and figure out how many days into the following week we are.
4. adjust your base date (the base of your subtraction) to accomodate whatever adjustments your company is requiring.
PRINT MYSMARTDATE AND
COMPUTE MYBASEDATE/YYMD=20030101;
COMPUTE DAYSTHISYR/I5=MYSMARTDATE - MYBASEDATE;
COMPUTE WEEKNUMBER/I4= DAYSTHISYR/7;
COMPUTE DAYSINTOWK/I4= IMOD(DAYSTHISYR,7,'I4');
i love working with smart dates.
they're just serial dates integer5 in form and math is breeze with them.
December 21, 2003, 01:53 PM
GCohen
This is a perfect example of how I would use the new FOCUS option called DEFINE Function.

DEFINE FUNCTION name (parameter1/format1,..., parametern/formatn)
[tempvariablea/formata = expressiona;] . . .[tempvariablex/formatx = expressionx;]
name/format = [result_expression];
END

Its in the Reference Manual.