Hi there,
I have a requirement to get the date of All Saturdays and Sundays in a year,
please let me know if there is a way to do it.
Discussion posts and replies are publicly visible
try this
a!localVariables( /* Define the year for which you want to get the dates */ local!year: 2023, /* Define the start for the year */ local!startDate: date(local!year, 1, 1), /* Get the number of days for the year*/ local!daysInYear: if(isleapyear(local!year),366,365), /* Iterate through each day in the year */ a!forEach( items: enumerate(local!daysInYear), expression: a!localVariables( /* Get the current date */ local!date: adddays(todatetime(local!startDate), fv!item), /* Check if the current date is a Saturday or Sunday */ if( Weekday(local!date,2) = 6 /* Saturday */, a!map(day:"saturday",date:todate(local!date)), if( weekday(local!date,2) = 7 /* Sunday */, a!map(day:"sunday",date:todate(local!date)), {} ) ) ) ), /* Display the list of Saturday and Sunday dates */ )
a!forEach( items: enumerate(if(isleapyear(year(today())), 366, 365)), expression: if( contains( { 1, 7 }, weekday( date(year(today()), 1, 1) + (day() * fv!item) ) ), date(year(today()), 1, 1) + (day() * fv!item), {} ) )
In order to fetch Saturday and Sunday, i believe it should be {1,2}, instead of {1,7}
a!forEach( items: enumerate(if(isleapyear(year(today())), 366, 365)), expression: if( contains( { 1, 2 }, weekday( date(year(today()), 1, 1) + (day() * fv!item) ) ), date(year(today()), 1, 1) + (day() * fv!item), {} ) )
weekday(date, return_type)
Returns the day of the week of the specified date or datetime.
Returns: Number (Integer)
date (Date): The date or datetime that the day of the week will be calculated from.
.return_type: '1' correlates 1 ... 7 with Sunday ... Saturday (this is the default). '2' correlates 1 ... 7 with Monday ... Sunday. '3' correlates 0 ... 6 with Monday ... Sunday.
Totally depends on the calendar you are using and which day you start your week with.