Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

First Sunday

Explorer ,
Feb 09, 2011 Feb 09, 2011

I want to send a scheduled email on the Friday before the first Sunday of each month.

I presume if I can find the first Sunday I can do a simple dateadd to get the Friday - I just need to learn how to find the first Sunday.

Thanks

931
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 09, 2011 Feb 09, 2011

Start by googling "coldfusion date functions".  When you see a page that lists them all, read each one and think of which ones might be useful.

Personally, I'd start with createdate, dateadd(), now(), year(), month(), and dayofweek().  But that's just me.

If you are having trouble figuring out the logic, drawing a flowchart might help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 09, 2011 Feb 09, 2011

Working out the date of the first day of the month is easy 😉

Working out which day of the week that happens to be is a single function call.

Working out the offset from that DOW to the nearest following Sunday is a simple mathematical expression

Ditto working out where the preceding Friday lies.

Dan's listed some functions to investigate...

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2011 Feb 12, 2011

<cffunction name="firstSundayOfMonth">
<cfargument name="month" required="yes">
<cfargument name="year" required="yes">

<cfset var dateFirstDayOfMonth = createDate(#arguments.year#,#arguments.month#,1)>
<cfset var firstDayWeekNumber = dayOfWeek(dateFirstDayOfMonth)>
<!---offset = number of days from first day to first Sunday--->
<cfset var offset = (8 - firstDayWeekNumber) mod 7>
<cfset var dateFirstSundayOfMonth = DateAdd("d", offset, dateFirstDayOfMonth)>

<cfreturn dateFirstSundayOfMonth>
</cffunction>


Date of first Sunday in June 2011 is <cfoutput>#firstSundayOfMonth(6,2011)#</cfoutput> (without format).<br>
Date of first Sunday in August 2010 is <cfoutput>#dateFormat(firstSundayOfMonth(8,2010),"dd mmm yyyy")#</cfoutput> (formatted).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 24, 2011 Feb 24, 2011

Thank you for all the helpful asnwers.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 24, 2011 Feb 24, 2011
LATEST

ctreeves wrote:

Thank you for all the helpful asnwers.

It's good to be helpful, it's even better to answer your question. Have we?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources