Notice: With the launch of Adobe Cookbooks, this site will no longer be accepting new entries or posting new content. Thanks to everyone who submitted content!

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 at 1:28:08 PM EDT.

CFML Referenced

Now()
<cfscript>

Categories

Dates/Times

Comments

There are no comments for this entry.