How to get a week numbers for a month?

1
Hello everyone,   I am getting the week number as per year if I use this function “formatDateTime($date,'w')”. But I need to get the week number of particular date of that month (like Week 1, 2, 3, 4 or 5) . Kindly tell me a solution for my problem.   Thank you.
asked
3 answers
13

Hi

You have to write some custom logic

AnyDate =  CurrentDataandTime

BeginOfCurrentMonth = beginOfMonth($CurrentDateandTime)

NoOfWeeks = round(weeksBetween($BeginOfCurrentMonth,$CurrentDateandTime))

 

 

 

Hope it helps!

answered
0

Hi,

  1. Create a custom microflow or use an expression to calculate the week number within a month. You can do this by first determining the day of the week for the first day of the month and then the day of the week for the date you want to calculate the week number for.

  2. Calculate the difference between the two day of the week values.

  3. Divide the difference by 7 to get the week number within the month.

// Input parameters:
$startDate: DateTime
$dateToCalculate: DateTime

// Get the day of the week for the first day of the month
$firstDayOfMonth = parseDateTime(formatDateTime($startDate, 'yyyy-MM-01'), 'yyyy-MM-dd')
$firstDayOfWeek = toInteger(formatDateTime($firstDayOfMonth, 'E'))

// Get the day of the week for the date to calculate
$dayOfWeek = toInteger(formatDateTime($dateToCalculate, 'E'))

// Calculate the week number within the month
$weekNumber = ceil(($dayOfWeek - $firstDayOfWeek + 1) / 7)

// $weekNumber now contains the week number within the month

 

You can call this microflow with the desired parameters to get the week number within the month for a specific date.

answered
0

Hi,

 

You can use

parseInteger(formatDateTime(date attribute, 'u'))

 

It will return an integer  which Monday=1 Tuesday =2 … Sunday=7

answered