Professional Web Applications Themes

Get last day of month - Coldfusion - Advanced Techniques

Hi, Is there a way to get the last day of each month using CFMX7 pls? E.g. I want to obtain the last day of each month, 30th June 2005 (30/06/2005), 31st July 2005 (31/07/2005) and so on. Is there a way to do that in CFMX7 pls? Thanks and regards, Yogesh Mahadnac...

  1. #1

    Default Get last day of month

    Hi,

    Is there a way to get the last day of each month using CFMX7 pls?

    E.g. I want to obtain the last day of each month, 30th June 2005 (30/06/2005),
    31st July 2005 (31/07/2005) and so on. Is there a way to do that in CFMX7 pls?

    Thanks and regards,

    Yogesh Mahadnac

    YogeshM Guest

  2. #2

    Default Re: Get last day of month

    Hello,

    You should go and take a look on:
    [url]http://www.cflib.org/udf.cfm?id=639[/url]

    I think that it is what you want to...

    I fact it is quite easy to do as you now pretty well for all the month over
    the year the only aspect to keep in mind is about february and leap years.


    maquejp Guest

  3. #3

    Default Re: Get last day of month

    There's a ColdFusion function called DaysInMonth() that will give you this. The
    parameter is a date object, so given a date such as July 1, 2005 the function
    would return 31 and you can create another date object for the last day in
    month.

    -Paul


    dempster Guest

  4. #4

    Default Re: Get last day of month

    A couple of other people have already answered, but I'll throw in my
    two cents and offer one more possible solution:

    dateAdd("d",-1,dateAdd("m",1,"1/06/2005"))

    The above example assumes European date formatting. It starts with
    June 1st (your sample data) and adds one to the month, resulting in
    July 1st. Then it subtracts one day, resulting in June 30th.

    christopher.secord@gmail.com Guest

  5. #5

    Default Re: Get last day of month

    Hi,

    That was not quite what I wanted.

    I've got a list of dates in my database (10th september 2004 up to now).
    Records are inserted on a daily basis. I needed to to do a query to get the
    last day of each month i.e. 30/09/2004, 31/10/2004, etc up to 30/06/2005 to do
    some additional calculations.

    Any suggestions?

    Yogesh Mahadnac

    YogeshM Guest

  6. #6

    Default Re: Get last day of month

    Try something like

    <cfset yr=Year(dateFromQuery)>
    <cfset m=Month(dateFromQuery)>
    <cfset d=DaysInMonth(dateFromQuery)>
    <cfset lastDayOfMonth=Createdate(#yr#,#m#,#d#)>
    BKBK Guest

  7. #7

    Default Re: Get last day of month

    Thanks!

    It really helped.

    Cheers...

    Yogesh Mahadnac
    YogeshM Guest

  8. #8

    Default Re: Get last day of month

    You can also do this in SQL before it gets to CF

    SELECT DATEADD(s, - 1, DATEADD(mm, DATEDIFF(m, 0, GETDATE()) + 1, 0)) AS LastDayOfMonth
    FROM some_table
    Mike Guest

Similar Threads

  1. Getting the day of the month
    By xyco45 in forum Macromedia Flex General Discussion
    Replies: 3
    Last Post: May 18th, 10:26 PM
  2. to convert a month to previous month
    By eddie wang in forum ASP
    Replies: 9
    Last Post: October 9th, 11:15 PM
  3. LAST DAY OF MONTH
    By Ralph Guzman in forum PHP Development
    Replies: 3
    Last Post: August 15th, 09:32 AM
  4. [PHP] LAST DAY OF MONTH
    By Ralph Guzman in forum PHP Development
    Replies: 1
    Last Post: August 15th, 08:57 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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