Coldfusion trouble with dates!

Posted on 2006-03-23
Last Modified: 2013-12-24
Hi Experts

Having endless trouble with dates in my coldfusion application. I am trying to use a cfinput type=” datefield” with a mask of “DD/MM/YYYY” to work with European dates.

The field passes the date in the correct format but when its entered into my database it is in the wrong format e.g. MM/DD/YYYY.

I have changed my input from a cfinsert into a cfquery insert into. This still does not solve the problem

<cfquery name="Insert" datasource="ILRData">
Insert into tblQual
(L03, Datesat, Qualification, Result, Mark, Certificate, Tutor, Project)
values (#L03#, #DateFormat(CreateODBCDate(Datesat), "DD/MM/YYYY")#, '#Form.Qualification#', '#Form.Result#', #Form.Mark#, '#Form.Certificate#', '#Form.Tutor#', '#Form.Project#')

After using the DateFormat and CreateODBCDate fields the query is only passing the time into the database.

Please help


Question by:clivecrawdevil
    LVL 24

    Expert Comment

    Did you try using the suffix _eurodate for you date field validation?

    Then also, if your database Datesat column is datetime - just let it insert how it wants and when you query the db for this date - then format it european or however you want.

    But to insert date - just use
    <CFQueryparam CFSqlType="CF_Sql_Date" value="#form.Datesat#">

    If your db date field is a type of text then use 'single quotes around form.Datesat'


    Author Comment

    Hi dgrafx

    I have already got eurodate as validation the problem appears to be on the action page when the data is inserted into the table.

    The problem is I am using the date in a grid on a flash form. And it always displays them funny (This is a known problem). Would the best way be to format the date when I call it in the query to populate the grid?

    Seems like an awfully tricky way of dealing with dates? What if I want to query the database directly, all the dates are in the wrong format? Is there another way to deal with European dates in coldfusion? I have an access database as the backend.


    LVL 24

    Expert Comment

    Read my above post again.
    The eurodate suggestion was just a suggestion.
    The answer lies in the remainder of the post.
    Don't worry about what the date looks like in the database - this doesn't affect you.
    Your only concern is being able to insert, update, & display - is that correct?

    Hope this helps ...

    Author Comment

    Sorry dgrafx it is causing me problems not being able to format the dates correctly, I have to run queries directly on this database and having the dates incorrectly formatted in the database causes information to be inaccurate.

    I have tried to find a solution but have not come across anything that works.

    Your help is much appreciated.


    LVL 24

    Accepted Solution

    I'm sorry about the difficulty and I did not know you are running queries on your db.
    You may need to change the date fields format to like short date - I think - experiment.
    Or how about (if that doesn't work) create different fields for each date part
    Like day is on col - month another etc

    Below is just a recap in case you no longer need to run queries on db.

    On your form you have
    cfinput type="datefield" with a mask of "DD/MM/YYYY"

    On your form action page you do an insert
    Insert Into table

    Then when you are viewing this record you have a query that selects DateSat
    Your output looks like this:
    #DateFormat(DateSat,"dd/mm/yyyy")# #TimeFormat(DateSat,"h:mm t")# (if you want time which would need to be specified on your original form or will be 12:00 AM)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
    Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
    The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: : Open Page or Post…
    The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now