formatting a date in cfselect

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default formatting a date in cfselect

    Assuming a query "meetingdate" that grabs a unique value of the 'meetingdate'
    field (a date/time field). In a form, that query is used to populate a cfselect
    command.

    The dropdown boxes now contain "yyyy-mm-dd hh:mm:ss" value (as in "2006-06-12
    12:23").

    How do I format the drop-down values into 'mm/dd/yy", as in "06/12/06" ? Using
    the formatdate in the 'display' argument of the cfselect command returns an
    error.

    Or, should the query command contain some sort of formatdate function (and
    what would that be)?

    Thanks....Rick...

    rhellewell Guest

  2. Similar Questions and Discussions

    1. Date Formatting
      Use the Day function. response.write day("12/1/2003") Of course, is that date the first of December, or the twelth of January? I suggest you...
    2. Formatting and sorting date
      I have an asp page which displays records from an access table. One of the fields in the table is a date field. The regional settings on the...
    3. formatting date
      On 30/7/03 2:18 PM, in article bg7guu$b7j$1@forums.macromedia.com, "JemJam" <webforumsuser@macromedia.com> wrote: The systemDate object will...
    4. Date - formatting
      I'm needing to assign the following variable with the following data from the date. Does anyone have any help they could offer please? date_day =...
    5. Date Formatting Issue
      I have Access 2000. On a form, I want to show (in an unbound text box) how long an agreement has been effect, and format it in years and days. ...
  3. #2

    Default Re: formatting a date in cfselect

    Use appropriate SQL functions to format the field in the query, would
    depend on the DBMS system you are using (MSSql, MYSql, Access, Oracle, etc).

    OR

    Use <select> instead of <cfselect> where you can use a basic loop to
    populate the <option> tags and format the date in the loop.

    OR

    Use a Query of Query or manually build a query out of the original query
    modifying the format of the date string and use this new query in the
    <cfselect> tag.


    rhellewell wrote:
    > Assuming a query "meetingdate" that grabs a unique value of the 'meetingdate'
    > field (a date/time field). In a form, that query is used to populate a cfselect
    > command.
    >
    > The dropdown boxes now contain "yyyy-mm-dd hh:mm:ss" value (as in "2006-06-12
    > 12:23").
    >
    > How do I format the drop-down values into 'mm/dd/yy", as in "06/12/06" ? Using
    > the formatdate in the 'display' argument of the cfselect command returns an
    > error.
    >
    > Or, should the query command contain some sort of formatdate function (and
    > what would that be)?
    >
    > Thanks....Rick...
    >
    Ian Skinner Guest

  4. #3

    Default Re: formatting a date in cfselect

    It's always better to do this kind of thing in the query.

    Here's the MS access syntax:
    SELECT
    Format(DATE_COLUMN, "mm/dd/yy") AS PurtyDate
    FROM
    YOUR_TABLE


    Other DB's are similar.


    MikerRoo Guest

  5. #4

    Default Re: formatting a date in cfselect

    This works (thanks!)
    SELECT DISTINCT
    Format(DATE_COLUMN, "mm/dd/yy") AS PurtyDate
    FROM
    YOUR_TABLE

    but this doesn't
    SELECT DISTINCT
    Format(DATE_COLUMN, "mm/dd/yy") AS PurtyDate
    FROM
    YOUR_TABLE
    ORDER BY DATE_COLUMN

    and this doesn't
    SELECT DISTINCT
    Format(DATE_COLUMN, "mm/dd/yy") AS PurtyDate
    FROM
    YOUR_TABLE
    ORDER BY Format(DATE_COLUMN, "mm/dd/yy")

    Both throw the error:
    [Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft
    Access Driver] ORDER BY clause (meetingdate) conflicts with DISTINCT.

    (Intent is to have unique date_columns, sorted by date_columns, formatted as
    'mm/dd/yy')

    ...Rick...

    rhellewell Guest

  6. #5

    Default Re: formatting a date in cfselect

    SELECT DISTINCT Format(DATE_COLUMN,"mm/dd/yy") AS PurtyDate
    FROM YOUR_TABLE
    ORDER BY Format(DATE_COLUMN,"mm/dd/yy")

    does work.

    You must have something else going on with your real query.

    Attach the real query and attach the full error message (which includes
    generated SQL).



    MikerRoo Guest

  7. #6

    Default Re: formatting a date in cfselect

    This works (I may have typo'd the problem earlier)

    SELECT
    DISTINCT format(meetingdate,'m/dd/yy') as cmeetingdate
    from documents
    ORDER BY format(meetingdate,'m/dd/yy')

    with this (note the use of the alias for the display and value parameters

    <cfselect name="MeetingDate"
    size="1"
    message="Select the Meeting Date from the drop-down list"
    query="MeetingDateList"
    value="cmeetingdate"
    display="cmeetingdate"
    queryPosition="below"
    width="10">
    <option value="">*** any meeting date ***</option>
    </cfselect>

    rhellewell 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