Skip to main content
September 8, 2008
Question

Date and Time Question

  • September 8, 2008
  • 2 replies
  • 761 views
Hello all,

I have been trying to do a timesheet application. I would like to know how can I check if the first day of the week which falls in the previous month.

Our first day of the week is Sunday. For example, the first day of last week was August 31.

thanks
    This topic has been closed for replies.

    2 replies

    Inspiring
    September 9, 2008
    Note: Replace testdate with now() after testing the code

    <!--- Change the testdate as desired to test the code --->
    <cfset testdate = lsDateFormat("04/09/2008", "dd mmm yyyy") />
    <!--- Set nthday as testdate's numeric day of week --->
    <cfset nthday = dayofweek(testdate) />
    <!--- Calculate the date of first day of the week i.e. Sunday's date --->
    <cfset firstday = lsDateFormat(dateAdd("d", -(nthday-1), testdate), "dd mmm yyyy") />
    <!--- Now compare the month of testdate with previous Sunday's. If different, we can confirm we are in a new month --->
    <cfif dateCompare(testdate, firstday, "m") EQ 1>
    <p>We are in a new month!</p>
    <cfelse>
    <p>Still the same month.</p>
    </cfif>
    Inspiring
    September 8, 2008
    Your question is not clear, but the following functions might be useful.

    DateAdd
    now()
    dayofweek
    month