4 Replies Latest reply on Jun 11, 2018 7:44 AM by Bryce Larsen

# Convert integers to date

Hi,

I have multiple integers which I would like to convert to Dates.

I.e :

Week_num
Date (desired column)
101/01/2018
201/08/2018
......

My integers consist of numbers from 1 to 20, corresponding to week numbers in 2018.

I tried the following in a calculated field :

IF [WEEK_NUM]=1 THEN MAKEDATE(2018,01,01)

ELSEIF [WEEK_NUM]=2 THEN MAKEDATE(2018,01,15)

ELSEIF

...

END

Thank you very much !

• ###### 2. Re: Convert integers to date

I think this should work:

DATETRUNC("week", DATETRUNC("year", TODAY()))))

You can of course replace TODAY() with the relevant date as needed. I also truncate it to the start of the week that contains January 1st, but unsure if this is desired. As such, the start of the first week for 2017 is actually 12/26/2016 since the 1st is on a Sunday (presuming your Week Start is Monday due to wanting 1/1/2018 as your first week in the post.

Best of luck!

1 of 1 people found this helpful
• ###### 3. Re: Convert integers to date

Thank you Bryce, this is exactly what I wanted. I will deep into the code to know exactly how it works, but thanks for putting it out there for me !

Have a good day.

• ###### 4. Re: Convert integers to date

To break it down you can go from inside-out.

DATETRUNC("year", TODAY()) returns 1/1/2018 (first day of the year).

DATETRUNC("week", ...) then returns 1/1/2018 (first day of the week, assuming you made week starting Monday on the dataset - right click - date properties - week start)

DATEADD("week", [WeekNum]-1, ...) will add N weeks to the date, but we subtract 1 since WeekNum starts at 1 rather than 0.

Wrapped it all within DATE() because we want it to just be a Date not a DateTime.

Hope this helps!

1 of 1 people found this helpful