Skip to main content
Inspiring
June 9, 2008
Question

How to find a particular date?

  • June 9, 2008
  • 10 replies
  • 1716 views
updated.
    This topic has been closed for replies.

    10 replies

    Inspiring
    June 12, 2008
    > Step 2 - create a while (aka conditional) loop. Inside this loop, add a day
    > to your date variable until the day of the week is the one you want.

    But you don't need to loop around to find it, you already know it.

    If the first day of the month is a Tues (DOW:3), then Thursday is going to
    be offset from that by 2, because Thurs is DOW:5. You don't need to loop
    through Tues and Weds to check if they are Thurs: they're not. you already
    know this.

    So the process is:

    What's the DOW of July 1?
    dayOfWeek(createDate(2008,7,1)) = 3 (Tue)

    If you want Thurs, then it's the 5th day of the week, which is 5 - 3 = 2
    days offset from the date of the 1st of the month.

    And the second Thurs is +7 days from that (ie: a week later).

    There's no loop necessary here.

    --
    Adam
    Inspiring
    June 12, 2008
    I thought that whole offset thing was an unnecessary complication. If you want a generic function here is the logic. You can write the code.

    Problem, get the nth X-day of the month containing sample_date.

    Step 1
    Create a date variable for the 1st day of the month containing sample_date.

    Step 2 - create a while (aka conditional) loop. Inside this loop, add a day to your date variable until the day of the week is the one you want.

    Step 3 - add (n - 1) * 7 days to your date variable. This gives you the correct answer.

    Adam Cameron has already told you what functions you need to do this.
    AdomacroAuthor
    Inspiring
    June 12, 2008
    Thanks Azadi,

    Works great...

    Yes..Azadi i got more requirement of same functionality.

    Like third wednesday of evey month.

    Fourth tuesday of every month.

    Is it possible to make this generic and work fine?.

    i am little confused with 14 + offset adding logic. How you count that?.

    If you can create a generic script and post here...that is great help.

    Please in cflib too....let ur name shine there too.

    i am going to recommend point system in this forum recognize good work people like Azadi is doing for this forum.
    Inspiring
    June 11, 2008
    show me what you have tried to do and i will show you how to do it so
    that it works...

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/
    AdomacroAuthor
    Inspiring
    June 11, 2008
    thanks Azadi...

    Please see my code and result...not working for date passed.
    ------------------------------------------------------------------------------------------------------------------------

    Result

    DOWFirstofMonth : 1

    AptDate : June 12, 2008 -- Correct for this month

    Compresult : 1

    Nextmonth : {ts '2008-07-13 00:00:00'}

    NextmonthDayOfWeek : 3

    AptDate : July 14, 2008 -- not correct (Result is suppose to be July 10, 2008)
    --------------------------------------------------------------------------------
    Inspiring
    June 10, 2008
    > no custom tag for this?.

    FFS. It's like three lines of code, the gist of which I've already given
    you, and pointed you to the functions you need to use. Just do it yerself.

    --
    Adam
    AdomacroAuthor
    Inspiring
    June 10, 2008
    where i can get this custom tag? link is not working.

    CF_CalcWeek

    http://www.cfcustomtags.com/subcategories.cfm?parentid=182
    AdomacroAuthor
    Inspiring
    June 10, 2008
    no custom tag for this?.
    Inspiring
    June 9, 2008
    Find the DOW of the first of the month.
    Determine the offset between that and the DOW that which you want to find.
    Add that to the date of the 1st of month.
    Add another week.

    Read the docs for:
    createDate()
    dayOfWeek()
    dateAdd()

    --
    Adam
    AdomacroAuthor
    Inspiring
    June 9, 2008
    How can i find 2nd thursday of every month.

    if current date is less than june 12th 2008.
    2nd tursday for june is June 12, 2008

    If current date is more than june 12th 2008.
    2nd tursday is July 10, 2008

    How can do this calculation?.


    How to find this date?.
    Inspiring
    June 9, 2008
    Step 1, get the day of the week for the first of the month. See if it's a Thursday.

    Start adding days and checking to see if the new date is a Thursday. Stop when you have found two Thursdays.

    Google "coldfusion date functions" if you don't know what functions to use.