Hi Team,
I want to get first day of the week by given week number and year.
Example: 0523 then it should return 30/01/2023.
I have tried below code, but it is returning 29/01/2023. Please suggest where i am doing wrong.
public static date Week2Date(int year, int week)
{
int yr = year;
xSession xSession = new xSession();
Date testDate = DateTimeUtil::getStartOfYearDate(xSession.PreferredLocale(),str2Date(strFmt("%1-01-01", yr), 321));
Int weekdays;
int wktmp = (week>1)? (week -1)*7 : 7;
testdate = datetimeutil::date( datetimeutil::addDays(datetimeutil::newDateTime(testdate,0) , wktmp));
if (DateTimeUtil::getWeekOfYear(xSession.PreferredLocale() ,testDate) != week)
{
if (week > DateTimeUtil::getWeekOfYear(xSession.PreferredLocale() ,testDate))
{
weekdays = 7;
}
else
{
weekdays = -7;
}
while (DateTimeUtil::getWeekOfYear(xSession.PreferredLocale() ,testDate) != week)
{
testDate = testDate weekdays;
}
}
return DateTimeUtil::getStartOfWeekDate(xSession.PreferredLocale() ,testDate);
}