Focal Point
[SOLVED] Get Week Number from Date in YYMD Format

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

June 18, 2009, 03:48 PM
Amber
[SOLVED] Get Week Number from Date in YYMD Format
I am trying to get the week number, or even ISO date. The original field was in Julian (YYYYDDD) format. I have that converted it to Gregorian (YYMD) format.
Using the 'Help' section in Dev Studio, I found the section on HYYWD.
COMPUTE ISODATE/A10 = HYYWD(TRANSDATE, 'A10');
COMPUTE WEEK/A2 = EDIT(ISODATE, '$$$$$$99$$');
I've tried using EDIT to edit the format of my date from YYMD to HYYWD, but that's not working at all. I was thinking about concatenating a time on the end of my date, but there should be a way to convert using just the date without a time. Help!

This message has been edited. Last edited by: Kerry,


WebFOCUS 768
OS/400
HTML, also quite a few active reports and excel.
June 18, 2009, 04:00 PM
trob
From what I recall to work with weeks its best to use a DateTime calculation. I believe the -SET WEEKFIRST only works with the DateTime functions. You can control what day is the start of the week and IIR they have recently fixed some of the ISO discrepancies with it. Now there is 1-7 and ISO1-ISO7.

I'm starting with &YYMD which is I8YYMD format.

 COMPUTE CUR_DATETIME/HMDYYS = HDTTM(DATECVT(&YYMD,'I8YYMD','YYMD'),8,'HMDYYS');
 COMPUTE CUR_WEEK_NO/I2 = HPART(CUR_DATETIME,'WEEK','I2');


This should output the week number in I2 format based on the WEEKFIRST setting.

This message has been edited. Last edited by: trob,


------------------------------------------
DevStudio 8.2.03
WFS 8.2.03
June 18, 2009, 04:39 PM
trob
DOWK AND DOWK returns the day of week and I believe Amber is looking for the actual week number of the year.

Amber,
I changed my code to include moving from an INT date to datetime, then from datetime to week number.

If your going to be working with dates I would recommend getting familiar with DATECVT if you are not already. It has to be my most used function when working with dates.

Also, just curious. I see your on OS/400, what is the source (application) of your original date field?


------------------------------------------
DevStudio 8.2.03
WFS 8.2.03
June 18, 2009, 05:36 PM
Doug
Thanks for the heads up on the DOW thing Trob, I removed it...

Keep in mind that these COMPUTEs (Posted Thu Jun 18 2009 16:00) are based on week one being the first FULL week of the year. Check it out with the EMPLOYEE file / HIRE_DATE and see what week Richard Smith was hired (Monday 01/04/1982). This says Week One, based on the first full week in 1982. 1/1/1982 is Friday of the previous week. I've been at places that required that week one was based on the first day of the year. If so, some trickery may be required. The code which shows this is available.
June 18, 2009, 06:11 PM
trob
quote:
Originally posted by Doug:
Thanks for the heads up on the DOW thing Trob, I removed it...

Keep in mind that these COMPUTEs (Posted Thu Jun 18 2009 16:00) are based on week one being the first FULL week of the year. Check it out with the EMPLOYEE file / HIRE_DATE and see what week Richard Smith was hired (Monday 01/04/1982). This says Week One, based on the first full week in 1982. 1/1/1982 is Friday of the previous week. I've been at places that required that week one was based on the first day of the year. If so, some trickery may be required. The code which shows this is available.


Nice point Doug. This is why they added the ISO1-ISO7. About a year and a half ago when I wanted to use ISO for week number it was broken but now its fixed. ISO 8601 standard week numbering defines the first week of the year as the first week in January with four or more days. It use to only work for the first week in January with seven days. That always made every day of week one a January date. With ISO week 1 can contain the last three days of December. Coding around that sucked at the time. Thank you IBI!

ISO is a synonym for ISO2 which is the ISO standard which establishes Monday as the first day of the week.


------------------------------------------
DevStudio 8.2.03
WFS 8.2.03
June 18, 2009, 08:25 PM
Doug
So, it comes down to what ISO do you want? Take your pick... You should have enough information now to get you going, right?
June 19, 2009, 12:45 PM
Amber
Yes sir(s) I have. I ended up using:

HRDT1/I8YYMD=GREGDT(DRHDAT, 'I8YYMD');
HRDT2/MDYY=HRDT1;
HRDT3/HYYMDS=HDTTM(HRDT2, 8, 'HYYMDS');
HRWK1/I2=HPART(HRDT3,'WEEK','I2');

DRHDAT is my Julian Date from the 400 (YYYDDD).

Thanks for all your help!!


WebFOCUS 768
OS/400
HTML, also quite a few active reports and excel.
June 19, 2009, 02:00 PM
trob
quote:
DRHDAT is my Julian Date from the 400 (YYYDDD).

Ok.
I was just wondering because we are on JDEdwards and all the dating in a modified julian format. Prior to Y2K fixes date fields were YYDDD however now it uses CYYDDD. C is 0 for years before 2000 and 1 for 2000 through 2099. Today is 109170.

Having to handle dates so often I found it well worth it to create a function on the server "JDETOSD()", which I pass it a JDE Julian Date and it returns a SmartDate.


------------------------------------------
DevStudio 8.2.03
WFS 8.2.03
June 19, 2009, 03:06 PM
Doug
Trob: Would you care to share th JDETOSD function with us, All the FocalPoint user?
June 19, 2009, 03:54 PM
trob
quote:
Originally posted by Doug:
Trob: Would you care to share th JDETOSD function with us, All the FocalPoint user?

Handling JDEdwards dates


------------------------------------------
DevStudio 8.2.03
WFS 8.2.03
June 20, 2009, 01:17 PM
Doug
Thanks trob...