Skip to main content

How to calculate last Friday or current day of the week? Is there any weekday function available?

Hi ​@akshayl09,

You can use toString function to get the name/number of the current day of the week using SimpleDateFormat (Java Platform SE 8 ) notion. Naming and numbering are dependent on the locale used (e.g. 1 is Sunday in US, Monday in GB). And then create a conditional logic to calculate the last Friday.

Alternatively, if your dates reliably lie within certain range, you can use some known Friday and calculate weeks from it. E.g. if valid dates are in this century, you can use following expression.

dateAdd(toDate('31-12-1999','dd-MM-yyyy'), (dateDiff(toDate('31-12-1999','dd-MM-yyyy'), in_dt, 'DAY') div 7) * 7, 'DAY')

 


Thanks ​@AKislyakov , It works.


Reply