Jump to content
  • 0

Display Current Week Date Range for particular date


thead

Question

Hi,

We have a date field, and would like to show in Calculated Field from which date to which date this week is. For example, if the date is in 1st week of February 2022, we want to show '01.02.2022 - 06.02.2022'.
Another example:
date: '8 March 2022', calculated value: '07.03.2022 - 13.03.2022'

Is this possible?

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Hi Thead,

Yes that is possible. First you will need to use the function "DATEPART(dw, [@field:DateField])" which will return integer from 1 to 7, based on which day of the week it is. 1 is Monday, 7 is Sunday.

When you have this value, you can use it in a formula in the next way, "[@calcfield:1]" will be the result of "DATEPART(dw, [@field:DateField])":

Calculate Monday in a given week: "DATEADD(day, -[@calcfield:1]+1, [@field:DateField])"
Calculate Sunday in a given week: "DATEADD(day, 7-[@calcfield:1], [@field:DateField])"

Altogether, without using additional fields, everything can be summed up in one Calculated Field with formula:

'Week from' + space(1) +
CONVERT(VARCHAR, (Dateadd(day, -Datepart(dw, [@field:DateField])+1, [@field:DateField])),101)
+ space(1) +
'to' + space(1) +
CONVERT(VARCHAR, (Dateadd(day, 7-Datepart(dw, [@field:DateField]), [@field:DateField])),101)

 

Hope this helps.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...