Skip to main content
Inspiring
July 18, 2008
Answered

Get all Sundays in a month

  • July 18, 2008
  • 1 reply
  • 1757 views
Hello,

I have a project where I have to generate a report based on week ending on Sundays for a month. In my db I have a column of week ending dates. I am really confused about how do I get the date for all the sundays for a particular month, query the db for those dates and output the data as a report like an excel format with each column being a week ending date and the rows under that column has the data for that week ending.

Please help.

Thank you
    This topic has been closed for replies.
    Correct answer Dan_Bracuk
    Use dayofweek on the 1st day of that month.

    Then add the correct number of days to get the first Sunday. Start a list of dates with that date.

    Keep adding 7 days and list appending until you get to the end of the month.

    That's the easy part.

    For the rest of it, depending on what data you are selecting, you can either do a fancy query that ends up with your dates as column aliases,
    or
    run a normal query, re-arrange it into an array and output the array.

    1 reply

    Dan_BracukCorrect answer
    Inspiring
    July 18, 2008
    Use dayofweek on the 1st day of that month.

    Then add the correct number of days to get the first Sunday. Start a list of dates with that date.

    Keep adding 7 days and list appending until you get to the end of the month.

    That's the easy part.

    For the rest of it, depending on what data you are selecting, you can either do a fancy query that ends up with your dates as column aliases,
    or
    run a normal query, re-arrange it into an array and output the array.
    Inspiring
    July 18, 2008
    But this is going to be dynamic. The user will select the month/year from a drop down and based on that I have to create the report. If i get the first day of the month how will I know how many days to add to get Sunday ?

    Thanks for the quick reply.
    Inspiring
    July 18, 2008
    quote:

    Originally posted by: voodoofrdr
    But this is going to be dynamic. The user will select the month/year from a drop down and based on that I have to create the report. If i get the first day of the month how will I know how many days to add to get Sunday ?

    Thanks for the quick reply.

    In addition to what Ian and Phil said, the createdate function will probably come in handy.

    To find out how to use any function we tell you about, google "coldfusion name_of_function x" where x is the version of cold fusion you are using. Whenever I do that, the 1st offering is the section of the cfml reference manual I want. If we suggest a tag, google "<cfTagName> x" to get similar results.