NTS Forums

Please login or register.

Login with username, password and session length
 

News:

Welcome to the Newtek Technology Services Forum!


Author Topic: Date display from MS SQL  (Read 1077 times)

Offline tmccartney66

  • Newbie
  • *
  • Posts: 18
  • Karma: +0/-1
Date display from MS SQL
« on: February 04, 2010, 10:35:07 AM »
We just upgraded our account, going from CF6 to CF8 and from MS SQL 2000 (I think) to MS SQL 2005.

One of the features of our site is a court case database that allows users to search for a case name and have a list of results come up.  The date field in the list of results is pretty messy - it looks like this:

2009-12-09 00:00:00.0

It used to be much friendlier, although I can't remember exactly how it was outputting before.  I'd prefer MO-DAY-YEAR or Dec. 12, 2009.

The CF code that creates that results display hasn't changed, so I have to assume I need to tweak this in the database itself; the date is pulled from the "CaseDate" field with data type datetime.  I'm not incredibly well-versed in MS SQL, but I do have SQL Server Management Studio Express.

Any suggestions on where to start?

Thanks!
« Last Edit: February 04, 2010, 10:37:26 AM by tmccartney66 »

Offline r937

  • Sr. Member
  • ****
  • Posts: 968
  • Karma: +29/-1
    • http://r937.com/
Re: Date display from MS SQL
« Reply #1 on: February 04, 2010, 10:53:17 AM »
best practice is to do custom formatting in the application, not in the SQL

use coldfusion's DateFormat() function

Offline MorningZ

  • Hero Member
  • *****
  • Posts: 5,366
  • Karma: +124/-25
    • My Neglicted Personal Website
Re: Date display from MS SQL
« Reply #2 on: February 04, 2010, 01:03:32 PM »
also check out SQL's "CONVERT" functionality

http://www.mssqltips.com/tip.asp?tip=1145

So if you have a date column where a value is:

2009-12-09 00:00:00.0

Saying

SELECT CONVERT(varchar, DateColumn, 107) FROM Table

will give you

Dec 09, 2009
"When I get fired, i want people to say: Wow! did that guy get canned!!!!" - George Castanza

"if you have one bucket that holds two gallons and another bucket that holds five gallons... how many buckets do you have?" - Mike Judge's Idiocracy

Offline ak732

  • Happily Verbose
  • Hero Member
  • *****
  • Posts: 1,476
  • Karma: +217/-39
    • Agile Web Technologies
Re: Date display from MS SQL
« Reply #3 on: February 04, 2010, 01:11:23 PM »
If your website will be viewed by people out side the US (where CT's database server is located), then it's a good idea to let the DB server store and return the date and then use your client software (ColdFusion in this case) to format the date in the locale-specific fashion of the viewer instead of hard-coding it anywhere (particularly in a SQL query - which is, I think, what Rudy was saying).
Andy

Offline r937

  • Sr. Member
  • ****
  • Posts: 968
  • Karma: +29/-1
    • http://r937.com/
Re: Date display from MS SQL
« Reply #4 on: February 04, 2010, 03:35:08 PM »
spot on, andy

presentation belongs in the application layer

Offline tmccartney66

  • Newbie
  • *
  • Posts: 18
  • Karma: +0/-1
Re: Date display from MS SQL
« Reply #5 on: February 05, 2010, 08:34:31 AM »
Thanks, guys.  I have no idea how to implement what you've suggested, but I'm already looking for a CF consultant, and I will ask him or her to put this on the list of things to be fixed.



Tracey

Offline Cliff

  • SM5 Beta Tester
  • Full Member
  • ****
  • Posts: 588
  • Karma: +5/-2
    • BloodBankTalk
Re: Date display from MS SQL
« Reply #6 on: February 05, 2010, 12:44:53 PM »
Tracey,

In your first post you mentioned "The date field in the list of results is pretty messy - it looks like this: 2009-12-09 00:00:00.0"

Somewhere on that page is something that look like this:
<cfoutput>#DateField#</cfoutput>

This is showing the date field from the database.

To make it look "friendlier", try this:
<cfoutput>#DateFormat(DateField, 'mmm. dd, yyyy')#</cfoutput>

That should display how you prefer.

Keep in mind what ak732 said about locale-specific if that applies to you.