DateFormat() accepts a date object and, optionally, the format in which you
want to _display_ the date.
If you pass it a string instead of an actual date object then CF tries to
convert it to a valid date, first using the mm/dd/yyyy format, and if that
fails it tries dd/mm/yyyy.
IsDate() does the same sort of thing, and so do some databases...

If you get a date passed as a string (eg from a form), then the _first_
thing you should do IMHO is use CreateDate() to turn it into a date object.

And only use DateFormat() when you're displaying a date and not to set a
variable, because you then run the risk of that variable being used
incorrectly elsewhere by someone who doesn't know what format mask you used
when you created the string.

ie 
good: <cfset mydateobject =
CreateDate(ListLast(form.date,'/'),ListGetAt(form.date,2,'/'),ListFirst(form
..date,'/')>
good: #DateFormat(mydateobject, 'dd/mm/yyyy')#    
risky: <cfset mydate = DateFormat(mydateobject, 'dd/mm/yyyy')>
bad: <cfset mydateobject = CreateDate(form.date,'dd/mm/yyyy')>
bad: IsDate(form.date)

Bert

Certified CF Developer who spent a lot of time tidying up shoddy date
handling written by someone else...

> -----Original Message-----
> From: Tim Price [mailto:[EMAIL PROTECTED]]
> Sent: 07 April 2001 09:17
> To: Fusebox
> Subject: Date fields
> 
> 
> Could anyone shed any light onto why after entering a date of 
> "07/04/2001"
> (dd/mm/yyyy format)the following <cfset
> display_from=#dateformat(display_from,"dd/mm/yyyy")#>
> switches it to "04/07/2001" (this is only used to redisplay 
> it if the form
> is redisplayed follwoing validation failure on any form field)
> 
> ..... unless that is I enter a day > 12 and then it retains 
> its original
> input "13/04/2001"
> 
> I also find that if I insert the field into the database without using
> CreateODBCDate it retains its orginal format but WITH 
> CreateODBCDate it
> switches the dd/mm parts round if the dd is < 13
> 
> Thanx in advance
> 
> Tim Price
> 
> 
> 
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to