Re: Date format issues
I agree with Paul and see no reason not to use LSParseDateTime.Macromedia (and Allaire) are American companies.In the future, I don't see them changing the standard (I use that very loosely) way in which CF stores dates (which is the U.S. format).If they did, backwards compatibility would with CF apps build for older versions wouldn't work.Anyways, CF datetime object are always MM/DD/ and that is how it's done.Luckily for you, CF has BIFs that can display those dates in different formats for you. I think you'd be better off parsing all of your dates into the CF format of DD/MM/ and then out putting them in the format you prefer or need.You could make a couple of UDFs or CFC to do your datetime functions so you.This way you can change the way you wish to format something or another in only one place.I won't go into that any more. Also, in the future, you might be interested in a TimeZone conversion CFC to do time conversions that CF doesn't support natively (with the help of Java objects).Things like this always us the standard date format. That's my two cents, .Peter MaePub [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Date format issues
I am trying to format two dates but I'm getting the days and months swapped around. e.g. cfset date1=02/08/2004 2nd August 2004 (in Australia) cfset date2=12/08/2004 12th August 2004 (In Australia) cfoutput date1 is #DateFormat(date1, 'dd/mm/')# - #DateFormat(date1, 'dd mmm ')#br date2 is #DateFormat(date2, 'dd/mm/')# - #DateFormat(date2, 'dd mmm ')#br /cfoutput This gives... date1 is 08/02/2004 - 08 Feb 2004 date2 is 08/12/2004 - 08 Dec 2004 Is there away of using the dd/mm/yy date format instead of US version. I don't want to have to parse the date string and use createdate. Thanks [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: Date format issues
lsDateFormat ? On Wed, 25 Aug 2004 09:59:10 +1000, Paul Wilson [EMAIL PROTECTED] wrote: I am trying to format two dates but I'm getting the days and months swapped around. e.g. cfset date1=02/08/2004 2nd August 2004 (in Australia) cfset date2=12/08/2004 12th August 2004 (In Australia) cfoutput date1 is #DateFormat(date1, 'dd/mm/')# - #DateFormat(date1, 'dd mmm ')#br date2 is #DateFormat(date2, 'dd/mm/')# - #DateFormat(date2, 'dd mmm ')#br /cfoutput This gives... date1 is 08/02/2004 - 08 Feb 2004 date2 is 08/12/2004 - 08 Dec 2004 Is there away of using the dd/mm/yy date format instead of US version. I don't want to have to parse the date string and use createdate. Thanks [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: Date format issues
Here is an explanation of the problem. When you set: cfset date1=02/08/2004 date1 is only a string, not a date. But when you say: DateFormat(date1,... you are calling a function that expects a date in input. So CF will try to convert the string into a date before it calls the function. (Here, for more details, please read this: http://www.contentbox.com/claude/customtags/convertDate/viewConvertDate.cfm?p=hf ) When converting a string to a date, CF will first suppose it is in American format, ie: mm/dd/ if it does not work, then it will try the ISO format dd/mm/yy. In your case, the American format works, and the date will be converted to 08 Feb 2004. To make sure you have no problem, use CF_dateConvert, or the UDF which come with the tag. By the way, this tag is free. -- ___ REUSE CODE! Use custom tags; See http://www.contentbox.com/claude/customtags/tagstore.cfm (Please send any spam to this address: [EMAIL PROTECTED]) Thanks. [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: Date format issues
if i understand what you mean try using the dateformat in your cfset cfset date1=DateFormat(02/08/2004, dd/mm/) cfset date2=DateFormat(12/08/2004, dd/mm/) cfoutput date1 is #DateFormat(date1, 'dd/mm/')# - #DateFormat(date1, 'dd mmm ')#br date2 is #DateFormat(date2, 'dd/mm/')# - #DateFormat(date2, 'dd mmm ')#br /cfoutput This will make date1 and date2 actual dates rather than a normal string to CF. Doing this tells CF that this is a date and what parts are what. - Original Message - From: Paul Wilson To: CF-Talk Sent: Tuesday, August 24, 2004 7:59 PM Subject: Date format issues I am trying to format two dates but I'm getting the days and months swapped around. e.g. cfset date1=02/08/2004 2nd August 2004 (in Australia) cfset date2=12/08/2004 12th August 2004 (In Australia) cfoutput date1 is #DateFormat(date1, 'dd/mm/')# - #DateFormat(date1, 'dd mmm ')#br date2 is #DateFormat(date2, 'dd/mm/')# - #DateFormat(date2, 'dd mmm ')#br /cfoutput This gives... date1 is 08/02/2004 - 08 Feb 2004 date2 is 08/12/2004 - 08 Dec 2004 Is there away of using the dd/mm/yy date format instead of US version. I don't want to have to parse the date string and use createdate. Thanks [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: Date format issues
DateFormat function is only for US formatted dates. Use LSDateFormat function which is for international dates and is already a BIF in CF.There is no need to use a custom tag to do something this simple See it at livedocs: http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/functa28.htm You can see all the LS type (international) funcations for MX here: http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/functi12.htm#wp1099325 HTH, .Peter maepub [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: Date format issues
This will make date1 and date2 actual dates rather than a normal string to CF. No, never. The function dateformat expects a date as first parameter, not a string, and 02/08/2004 is a not a date, it is a string. A date in CF is represented internally by a number. Even if the function iDate(02/08/2004) says yes, don't be confused. These type detection functions in a language like CF which is typeless is just a joke. It does not return yes or no this is a date, but Yes or no I could make this a date if you want it to be a date. Only true dates should be passed to dateformat, like for instance dateFormat (now(),... or dateFormat (createDate(...),... etc. -- ___ REUSE CODE! Use custom tags; See http://www.contentbox.com/claude/customtags/tagstore.cfm (Please send any spam to this address: [EMAIL PROTECTED]) Thanks. [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: Date format issues
By the way, if you work in America on servers set to the American date formatting standard on projects exclusively for an American audience, you might never run across this problem. I've worked around it by always inputting a date (from a form) in day month year parts (or splitting it up into the parts if it's a _javascript_ style calendar), and then connocating them into a single string in the format year-month-date, and then run CreateODBCDate() on that string. I've found this will work reliably no matter how the server is set up, dd/mm/ or mm/dd/, because i *think* CF(at least CF5) set up on a server using the european date system will try to make a european date out of the string first. (Thank you very much!) At least that's been my experience. So it can be a real mess if you're not sure where your app will be deployed, on a server in America or on a server elsewhere. On Tue, 24 Aug 2004 21:11:04 -0400, Ewok [EMAIL PROTECTED] wrote: if i understand what you mean try using the dateformat in your cfset cfset date1=DateFormat(02/08/2004, dd/mm/) cfset date2=DateFormat(12/08/2004, dd/mm/) [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: Date format issues
- Original Message - From: Claude Schneegans To: CF-Talk Sent: Tuesday, August 24, 2004 9:31 PM Subject: Re: Date format issues This will make date1 and date2 actual dates rather than a normal string to CF. No, never. The function dateformat expects a date as first parameter, not a string, and 02/08/2004 is a not a date, it is a string. A date in CF is represented internally by a number. Even if the function iDate(02/08/2004) says yes, don't be confused. These type detection functions in a language like CF which is typeless is just a joke. It does not return yes or no this is a date, but Yes or no I could make this a date if you want it to be a date. Only true dates should be passed to dateformat, like for instance dateFormat (now(),... or dateFormat (createDate(...),... etc. -- ___ REUSE CODE! Use custom tags; See http://www.contentbox.com/claude/customtags/tagstore.cfm (Please send any spam to this address: [EMAIL PROTECTED]) Thanks. [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: Date format issues
Use LSDateFormat function which is for international dates and is already a BIF in CF.There is no need to use a custom tag to do something this simple No, the problem here is not with formating the date. The only thing LSDateFormat does is to provide a different default mask, depending on the locale setting, and output days and month names in the local language. But whatever the local setting is, CF will still convert a string to a date the same way, ie assuming the date is in American format first. Just try the following code: CFSET temp = setLocale (English (Australian)) CFSET date1 = 02/08/2004 CFOUTPUT date1 is #LSDateFormat(date1, 'dd/mm/')# - #LSDateFormat(date1, 'dd mmm ')# /CFOUTPUT It will still claim the date is 08/02/2004 - 08 Feb 2004 In order to make sure the date is converted and passed correctly, you have only two solutions: 1. use create date on the string, ie: CFSET date1 = 02/08/2004 CFSET date1 = createDate(mid(date1, 7, 4), mid(date1, 4, 2), mid(date1, 1, 2)) Then date 1 is a date AND it is correct, ... or 2. use function convertDate : CFSET date1 = convertDate(date1, string, date, dd/mm/) If you prefer method 1, its up to you, I found more convenient to make convertDate once for all. convertDate is just a kind of unFormatDate function. The advantage is that YOU provide the mask, you don't let CF guess what format the date should be. -- ___ REUSE CODE! Use custom tags; See http://www.contentbox.com/claude/customtags/tagstore.cfm (Please send any spam to this address: [EMAIL PROTECTED]) Thanks. [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: Date format issues
guess that makes sense... either way, what I posted swaps the day and moth and changes your orginal output to August dates. I THINK that is what you wanted. I'm not getting into the inner workings of CF and its why's and how's because I only got 118 from the IQ discussion : ) - Original Message - From: Claude Schneegans To: CF-Talk Sent: Tuesday, August 24, 2004 9:31 PM Subject: Re: Date format issues This will make date1 and date2 actual dates rather than a normal string to CF. No, never. The function dateformat expects a date as first parameter, not a string, and 02/08/2004 is a not a date, it is a string. A date in CF is represented internally by a number. Even if the function iDate(02/08/2004) says yes, don't be confused. These type detection functions in a language like CF which is typeless is just a joke. It does not return yes or no this is a date, but Yes or no I could make this a date if you want it to be a date. Only true dates should be passed to dateformat, like for instance dateFormat (now(),... or dateFormat (createDate(...),... etc. -- ___ REUSE CODE! Use custom tags; See http://www.contentbox.com/claude/customtags/tagstore.cfm (Please send any spam to this address: [EMAIL PROTECTED]) Thanks. [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: Date format issues
Well, it's not such a mystery. Computer languages and OS's have no standardized way of representing dates, and neither do humans, and so in a somewhat misguided effort to make it easy, ColdFusion makes assumptions, and sometimes they're wrong. When you put all that together, the discrepancies tend to multiply a little. In the end for any date (or perhaps server configuration) in an app outside of the US, it's the programmer who has to indicate somehow this number represents the day this number represents the month and this is the year - please make a date out of that in ColdFusion datetime speak - you can ignore what the server thinks. I was reading an article about converting datetime from one computer language / OS to another ... now that's really a mess! Windows i think has a few variations, Java has one, Mac has one, IBM has one, different databases have different standards, Google has a fairly standard one, i see in the line below, etc etc. On Tue, 24 Aug 2004 22:22:19 -0400, Ewok [EMAIL PROTECTED] wrote: guess that makes sense... either way, what I posted swaps the day and moth and changes your orginal output to August dates. I THINK that is what you wanted. I'm not getting into the inner workings of CF and its why's and how's because I only got 118 from the IQ discussion : ) [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: Date format issues
cfset date1=02/08/2004 2nd August 2004 (in Australia) cfset date2=12/08/2004 12th August 2004 (In Australia) as strings, you actually might want to parse them (why the aversion to this function?) first to make them cf datetime objects prior to doing whatever w/them: cfscript dateStr=02/08/2004; setLocale (English (Australian)); // mightily stupid locale name ozDate=lsParseDateTime(dateStr); setLocale (English (US)); // mightily stupid locale name usDate=lsParseDateTime(dateStr); writeoutput( raw date := #dateStr# br / ozDate := #dateFormat(ozDate)# br / usDate := #dateFormat(usDate)# ); /cfscript [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: Date format issues
Nope, not a mystery at all. Seems to me that if its a number or a string or a basketball... if CF stores it as a date time object on a timeline.. then it's a date. I don't think it takes your average string and stores it as a date time object. Yes, im sure it uses numbers to reference it's position just like most anything else does. CF knows that what is there is exactly what it put there and hardly makes an assumption about it's value. like someone already said, you can change the default US to some others if you want making your defualt whatever you want it to be.But what it puts there is there and ther's no assumption about it's value. Except from us... I assume it's a date because I used date functions to create it so that's what I'm going to call it and use it as if that's ok. - Original Message - From: Nando To: CF-Talk Sent: Tuesday, August 24, 2004 10:44 PM Subject: Re: Date format issues Well, it's not such a mystery. Computer languages and OS's have no standardized way of representing dates, and neither do humans, and so in a somewhat misguided effort to make it easy, ColdFusion makes assumptions, and sometimes they're wrong. When you put all that together, the discrepancies tend to multiply a little. In the end for any date (or perhaps server configuration) in an app outside of the US, it's the programmer who has to indicate somehow this number represents the day this number represents the month and this is the year - please make a date out of that in ColdFusion datetime speak - you can ignore what the server thinks. I was reading an article about converting datetime from one computer language / OS to another ... now that's really a mess! Windows i think has a few variations, Java has one, Mac has one, IBM has one, different databases have different standards, Google has a fairly standard one, i see in the line below, etc etc. On Tue, 24 Aug 2004 22:22:19 -0400, Ewok [EMAIL PROTECTED] wrote: guess that makes sense... either way, what I posted swaps the day and moth and changes your orginal output to August dates. I THINK that is what you wanted. I'm not getting into the inner workings of CF and its why's and how's because I only got 118 from the IQ discussion : ) [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]