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);
}
Check out In .net, knowing the week number how can I get the weekdays date?, for instance.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,134 Super User 2024 Season 2
Martin Dráb 229,928 Most Valuable Professional
nmaenpaa 101,156