Skip to main content
July 11, 2008
Question

date problem

  • July 11, 2008
  • 6 replies
  • 1156 views
i have date like 02/02/02008
and i am using isdate function and its return true. any idea why?
Year has 02008 which is incorrect. so how can i validate that.

thanks
This topic has been closed for replies.

6 replies

Participating Frequently
July 29, 2008
There are plenty of date functions. If you are thorough the date function is very easy.
For music visit http://mp3katalog.eu
BKBK
Community Expert
Community Expert
July 14, 2008
isDate() has a broad interpretation. I suppose it's because it takes a string as argument, whereas there are countless ways to represent a valid Coldfusion date as a string. For example, the following will produce a 'yes': <cfoutput>#isDate('1a')#</cfoutput>

If you want to store dates to the database, you could follow Mr. Modus' advice and apply createODBCDate().
Participant
July 16, 2008
That's right, IsDate() is usually not the function you want to use in cases like this.

IsDate() will return true for anything that can be converted to a date value. It's not bad, as long as you don't care how the date is converted ... because many, many values can be converted to dates. (For example, just about any string that consists of numbers and separators.)

In most cases, you would want to perform some validation on the value so that you can have more confidence that the date parts are provided as you expect. This helps with day/month order as well as with years. After all, 12008 is a valid year, but I would guess that for Nick's purposes, it would not be something he would expect. (You must be careful with the validation you use ... for example, passing the string "02/02/12008" and using dateformat with the mask "dd/mm/yy" returns a date representing February 2, 2008. Using "dd/mm/yyyy" returns February 2, 12008.)
Inspiring
July 16, 2008
Agreed about the broad interpretations of IsDate.

Dave DuPlantis wrote:
> (You must be careful with the validation you use ... for example, passing the string
> "02/02/12008" and using dateformat with the mask "dd/mm/yy" returns a date representing
> February 2, 2008. Using "dd/mm/yyyy" returns February 2, 12008.)

Technically, no. The DateFormat functions expects a date time object and returns a string.

I suspect that is probably what was meant. But since the OP may be confused about strings versus date time values it is a point worth clarifying IMO.
Inspiring
July 12, 2008
Nick201, did that work for you?
Inspiring
July 11, 2008
I'm guessing you aren't turning the date into an ODBC format?

Try this:

<cfset myDate = CreateODBCDate("02/02/02008")>
July 11, 2008
because when i insert into db then it throw error because of 02008

how can handle @ db insert level.
Inspiring
July 11, 2008
Well, date functions in CF seem to ignore leading zero's. So 02008 is equal to 2008. Therefore it is a date.

What exactly are you trying to acheive here? If you want to disallow the value because it's more than four chars you could simply do this:

<cfif Len(ListLast("02/02/02008","/")) GT 4>throw error</cfif>

I wonder why it matters though, since you can work with 02008 the same as you can with 2008.

Perhaps you could give more detail about why you are trying to invalidate the data.