Subscribe Bookmark RSS Feed

Convert Work Week into Date (JMP10)

robot

Community Trekker

Joined:

Feb 27, 2012

Hi,

I have a data set that lists work week, and I am trying to convert this number into a calendar date.  I know JMP has a function to convert calendar date into work week, but I would like to do the opposite.

For example, I have a number like 201334, representing YYYYWW.  How can I convert this back into a date?  My reason is that I would like to be able to plot this data on a time trend, but without large gaps between years (for example from 201252 to 201301).

I am sure I can do this by calculating the number of seconds from 1/1/1904, but I am starting to get a headache trying to account for leap years, week starting days, and whatnot.  I hope there is an easier way to do this.

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
thechadd

Community Trekker

Joined:

Jun 23, 2011

Solution

I wrote a script for this based on how my previous company defined work weeks.  You can modify it to however you define work weeks where you are.

//Arguments:

//_ww_ = Work week, 1 to 53

//_year_ = Four digit year, e.g. 2004

//_dayofweek_ = 1-7 (1 = Sunday...)

::iwwtodate = Function(

     //Function Arguments

     {_ww_, _year_,_dayofweek_,

     //Local Variables

     _ww01thisyear_ = 0,

     _sundayww01_ = 0

     },

     _ww01thisyear_ = Informat("01Jan" || Char(_year_));

     _sundayww01_ =_ww01thisyear_ - (Day Of Week (_ww01thisyear_)- 1) * 24 * 3600;

     (_ww_ - 1) * 7 * 24 * 3600 +_sundayww01_ + (_dayofweek_ -1) * 24 * 3600

);

Message was edited by: Chadd McNicholas

2 REPLIES
thechadd

Community Trekker

Joined:

Jun 23, 2011

Solution

I wrote a script for this based on how my previous company defined work weeks.  You can modify it to however you define work weeks where you are.

//Arguments:

//_ww_ = Work week, 1 to 53

//_year_ = Four digit year, e.g. 2004

//_dayofweek_ = 1-7 (1 = Sunday...)

::iwwtodate = Function(

     //Function Arguments

     {_ww_, _year_,_dayofweek_,

     //Local Variables

     _ww01thisyear_ = 0,

     _sundayww01_ = 0

     },

     _ww01thisyear_ = Informat("01Jan" || Char(_year_));

     _sundayww01_ =_ww01thisyear_ - (Day Of Week (_ww01thisyear_)- 1) * 24 * 3600;

     (_ww_ - 1) * 7 * 24 * 3600 +_sundayww01_ + (_dayofweek_ -1) * 24 * 3600

);

Message was edited by: Chadd McNicholas

robot

Community Trekker

Joined:

Feb 27, 2012

Very handy!  Thank you for sharing.