• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

date problem

Guest
Jul 11, 2008 Jul 11, 2008

Copy link to clipboard

Copied

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
TOPICS
Advanced techniques

Views

967

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 11, 2008 Jul 11, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 11, 2008 Jul 11, 2008

Copy link to clipboard

Copied

because when i insert into db then it throw error because of 02008

how can handle @ db insert level.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 11, 2008 Jul 11, 2008

Copy link to clipboard

Copied

I'm guessing you aren't turning the date into an ODBC format?

Try this:

<cfset myDate = CreateODBCDate("02/02/02008")>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 12, 2008 Jul 12, 2008

Copy link to clipboard

Copied

Nick201, did that work for you?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 14, 2008 Jul 14, 2008

Copy link to clipboard

Copied

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().

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 16, 2008 Jul 16, 2008

Copy link to clipboard

Copied

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.)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jul 16, 2008 Jul 16, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 18, 2008 Jul 18, 2008

Copy link to clipboard

Copied

quote:

Originally posted by: -==cfSearching==-
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.


The date/time object can also be passed to DateFormat as a string ... I would say we are discussing a different issue, but I think it's related. It seems as though the OP is struggling with the difference between validation for CF's purposes and validation for the destination's purposes. The ability to pass a string when a date/time object is desired is nice in terms of flexibility, but it also complicates any attempt to explain the situation!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jul 25, 2008 Jul 25, 2008

Copy link to clipboard

Copied

Dave DuPlantis wrote:
> It seems as though the OP is struggling with the difference between validation for CF's
> purposes and validation for the destination's purposes.

Yes. That is the nature of using date strings versus date/time objects. The interpretation and conversion is handled by the parent application. So the conversion rules are very likely to differ from one application to another and the results may vary. That is why is usually not the best way to transfer date values from CF to a database.

As mentioned in earlier responses, the safer method is to use date/time objects, not strings. Then there is no ambiguity and you do not have to concern yourself with whether the database will interpret a date string differently than ColdFusion. For even greater control over how the values are constructed, the createDate and createDateTime functions are useful.

> The date/time object can also be passed to DateFormat as a string ...

Yes, but it expects / operates on a date/time object. That and the fact that it returns a string, not a date, are subtle but key distinctions.

> The ability to pass a string when a date/time object is desired is nice in terms
> of flexibility, but it also complicates any attempt to explain the situation!

Very true. I think it can also lead to confusion about the usage of some date functions. Take for example DateFormat. The fact that you can also pass in a string, letting CF handle the conversion, seems to give some people the wrong impression about what the function actually does. I read several recent posts where the individual mistakenly thought the DateFormat function converts a string to date/time object, and that the mask tells CF how to interpret the supplied string. It does not. So while this thread was not really about DateFormat .. a small clarification was warranted. Just in case future readers are similarly confused ;-)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 16, 2008 Jul 16, 2008

Copy link to clipboard

Copied

BKBK, are you able to help me with this problem I am having looping over an array?
http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?catid=7&threadid=1378713

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 28, 2008 Jul 28, 2008

Copy link to clipboard

Copied

LATEST
There are plenty of date functions. If you are thorough the date function is very easy.
For music visit http://mp3katalog.eu

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation