CFFEED and Date Values

This post is more than 2 years old.

I ran into an interesting issue this week with my work at Broadchoice and the RSS feeds that some of my code was generating. For some reason the times were off by multiple hours. It wasn't a database issue. When viewing the data in non-RSS mode it was perfect. But as soon as I switched to the RSS feed the problem was pretty bad. Because the hours were so far off, new data wasn't showing up in feed readers.

I did some reading (and remember, CFFEED isn't covered at all in the developer's guide - just the reference) and came across this note:

When the cffeed tag creates a feed, you can use W3C or RFC 822 formats for both feed types. You can also use any standard date or date/time format accepted by ColdFusion.

Now I read this as - "You can use a normal CF date and I'm cool with it." But that isn't the case. When I viewed source on the XML generated by CFFEED, the times were marked as GMT but were still in the original value. What I mean is, the time had originally been 1PM EST, but the XML said 1PM GMT, which is obviously way wrong.

Fixing this was a bit difficult. (And if folks know a simpler solution, speak up!) I began by using GMTDateFormat. This UDF takes a date and an offset value. It returns a time in GMT. The offset though can't be just a number. It had to be in the form of

+NNMM

or

-NNMM

So I knew I could get the offset using getTimeZoneInfo(). However, this returned a simple value, like 5, not +05. I ended up using this code:

<cfset var tz = getTimeZoneInfo()> <cfset var offset = numberFormat(tz.utcHourOffset,"00") & numberFormat(tz.utcMinuteOffset, "00")>

<!--- implies no - ---> <cfif len(offset) is 4> <cfset offset = "+" & offset> </cfif>

Once I did this - and used the UDF - my feeds started showing the right values. Maybe I'm crazy but it sure would be nice if this was handled by the tag for me.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by Sid Wing posted on 5/25/2008 at 1:38 AM

Ray - You are THE MAN! I've been fighting this issue with some internal feed generating apps that I wrote for work and have been thinking it was somehow related to the translation of datetime fields from SQL 2k5 to the formats supported by CF8.

And you're right... It would be easier (if the tag always generates GMT) to have an "offset" attribute in the tag itself. Maybe for 8.02 or 9?

Comment 2 by db posted on 5/25/2008 at 6:52 PM

i ran into tz offset mischief and decided to convert all dates to be viewed clientside to UTC.
i used DateConvert("local2utc", yourDate) on server dates and then some js to display on the page in the client timezone. it seems to be working ok.

Comment 3 by Raymond Camden posted on 5/25/2008 at 7:39 PM

I want to say I had issues with this - it should work though. I'll try it again on Tuesday. It would certainly be a lot slimmer. The only issue would be if your times were not in the same tz as your machine's tz.

Comment 4 by erik posted on 12/12/2008 at 12:32 AM

was having this same problem,but instead of using the above UDF and CF code i formatted the date column in the sql query to GMT and it worked great for me, heres the sql

,DATEADD(MINUTE,DATEDIFF(MINUTE,CURRENT_TIMESTAMP,GETUTCDATE()),date_published) AS 'date_published'