Date Range from Week Number

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Date Range from Week Number

    Has anyone ever tried to create a date range from a week number? Here is my
    scenario: I have a database with a primary key of weekNum. There are 52
    entries in this DB ranging from 1-52. I want to list out these entries as date
    ranges. For example: Week 9 (Feb. 20 - Feb. 26) Week 10 (Feb. 27 - Mar. 5)
    etc.... Any help or ideas would be greatly appreciated.

    Unamailer Guest

  2. Similar Questions and Discussions

    1. #39912 [NEW]: date('W') returns wrong week number for some dates
      From: pkus at epf dot pl Operating system: windows xp PHP version: 5.2.0 PHP Bug Type: *General Issues Bug description: ...
    2. Code for telling the week number on a specific date
      I've been annoyed that the Date class had no ability to tell which week a certain date fell within. So I created a function that will take any date...
    3. Covert Date to week number
      Is their a way in PERL to covert a date to a week number Cheers Neill
    4. Convert Date to week number
      Tim wrote: ISO8601 defines a standard, but not everyone follows it. See: ...
    5. Parsing a date from the week number of a given year from request post
      I'm trying to get the date from a request-query post that contains a year (request("season") and a week number from that year...
  3. #2

    Default Re: Date Range from Week Number

    Try the attached code for some ideas.

    <cfif IsDefined("form.bleah")>
    <cfset firstday = "01/01/"&datepart("yyyy",now())>


    <Cfset refday = dateadd("ww", form.checkdate -1 ,firstday)>

    <cfset thisday = refday>
    <CFSET first_day_of_last_week = DateAdd("d", (DayOfWeek(thisday)-1)*-1,
    thisday)>
    <CFSET last_day_of_last_week = DateAdd("d", 6, first_day_of_last_week)>
    </cfif>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

    <html>
    <head>
    <title>Untitled</title>
    </head>

    <body>
    <cfif IsDefined("form.bleah")><cfoutput>For week number #form.checkdate#,
    we use #firstday# as a reference (You can manipulate the reference date in
    line 2 of this script). #form.checkdate# weeks from this date is
    #dateformat(thisday,"mm/dd/yyyy")#, which
    is in the week from #dateformat(first_day_of_last_week,"mm/dd/yyyy")#
    - #dateformat(last_day_of_last_week,"mm/dd/yyyy")# , so
    #dateformat(first_day_of_last_week,"mm/dd/yyyy")#
    is the first day of week #form.checkdate#.


    </cfoutput></cfif>
    <form action="first_day_of_any_week.cfm" method="post">
    Enter week number:<input type="text" name="checkdate"><br>
    <input type="submit" name="bleah" value="Get date info"></form>


    </body>
    </html>

    philh Guest

  4. #3

    Default Re: Date Range from Week Number

    Phil:

    Thanks for the help! This worked like a champ!!!

    I was able to use the code that you provided and modify it for an exact solution.

    Thanks again!!!
    Unamailer Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139