When you use CreateODBCDate and pass in a string it will first try to
convert it to a date using the US format of mm/dd/yyyy, and only if that
fails will it try the "rest-of-the-world" format of dd/mm/yyyy. The same
goes for some of the other CF date functions.
So 12/13/2009 and 13/12/2009 will both get converted to 13th Dec 2009.
:|
IMO, the safest way to deal with dates coming in as strings (e.g. from forms
etc) is to convert them to CF dateobjects using CreateDate as soon as you
can using something like the following, though the error handling would
obviously do something more friendly than just abort.
<cftry>
<cfset myDateObject = CreateDate(ListGetAt(form.dateString, 3, '/'),
ListGetAt(form.date, 2, '/'), ListGetAt(form.date, 1, '/'))>
<cfoutput>#myDateObject#</cfoutput>
<cfcatch>
<cfabort showerror="i couldn't make a date out of form.date...">
</cfcatch>
</cftry>
Assuming that the datatype of your dB column is DATETIME, you'll want to do
something similar when displaying the date you pull out of the database,
this time using DateFormat(yourDate, 'dd/mm/yyyy'). (N.B. DateFormat should
be used to display a date object in a particular format, and not to try to
create a date object from a string in a particular format...)
As Peter mentioned, where possible it is preferable to use mmm is any dates
you display to the end user as this removes any ambiguity between dd/mm vs.
mm/dd: everyone understands Jan 2 2009 and 2 Jan 2009.
Cheers
Bert
On Tue, Apr 7, 2009 at 8:08 AM, alex poyaoan <[email protected]> wrote:
>
> HI everybody have this problem and could't get over it..
>
> I have a flash form that insert date on an mssql 2000 db the format that is
> on the db field is dd/mm/yyyy... I display the date on a form and it
> displays right without doing anything and press ok on the form it flips the
> day and month ex 01/02/2009 (feb 1 2009) now is 02/01/2009 the insert
> statementi is CREATEODBCDATE(FIELDNAME) AND THE UPDATE IS THE SAME..
>
> thanks
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to
date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f
Archive:
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:321401
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4