User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ColdFusion section within the Web Development category of DaniWeb, a massive community of 391,764 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,194 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ColdFusion advertiser:
Views: 1244 | Replies: 2
Reply
Join Date: Apr 2007
Posts: 28
Reputation: lafalot is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
lafalot lafalot is offline Offline
Light Poster

Sort integer as hour

  #1  
Aug 31st, 2007
Hi,

I have time stored as an integer in sql server. The time is separated into fields of hour, minute and am/pm. I need to output the data and sort the time, but of course, 12 is coming after 1. Is there a way to sort my hour integers in a time fashion?

Thank you!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2005
Location: Downingtown
Posts: 53
Reputation: hinde is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 3
hinde hinde is offline Offline
Junior Poster in Training

Re: Sort integer as hour

  #2  
Sep 1st, 2007
I personally would not go for this particular way of storing times. If I was faced with this paritcular problem from a site that I was asked to maintain, I would write a one-shot script that would:
1. Alter the table to have an odbc datetime.
2. Read in all records from this table.
3. Loop over this table, updating each record's new odbc datetime with a translated version of your integer.

You would still have this integer field and instead of doing something programmatically with coldfusion you would foist the work off on SQL server, which would make this sorting perform better.
Reply With Quote  
Join Date: Apr 2007
Posts: 28
Reputation: lafalot is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
lafalot lafalot is offline Offline
Light Poster

Re: Sort integer as hour

  #3  
Sep 1st, 2007
Thanks for your advice, hinde. I think your solution is probably more sound than the one I came up with. I'm just not that comfortable w/sql server, so what I did was create a table with 3 columns: hour, sort, and am_pm. I put all 1-12 & 1-11 in the hour column, sort order in the sort column, and am or pm in the am_pm column. So, the columns with one and pm has 13 as a sort. Then, I did an innerjoin on my hour and am/pm field in the tabe, and used the sort field to order by. It seems to be working.

Thanks again!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb ColdFusion Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the ColdFusion Forum

All times are GMT -4. The time now is 4:21 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC