How do you determine the beginning of a given week?

When building online calendars it's often useful to know the first day of the week for a given date. The following code returns the Sunday of the date provided. The code can easily be adjusted to return another day if required (see code comment).

<cfscript>
	request.startDate = now();
	currentDayOfWeek = dayOfWeek(REQUEST.startDate);
	offset = 1 - currentDayOfWeek;//change number to get a different weekday
	variables.startDate = createODBCDate(dateAdd("d", offset, request.startDate));
</cfscript>

This question was written by Oliver Merk
It was last updated on June 13, 2006.

Categories

Dates/Times

Comments

comments powered by Disqus