Date output format must NOT be converted to CHAR of any kind

Posted on 2011-03-08
Last Modified: 2012-05-11
Hi All

I have a table where the dateformat is stored in a INT field (A Cisco CDR table).

I can convert the date to a more readable format via this conversion:

SELECT CONVERT(varchar(11), (DATEADD(hh, 2, DATEADD(s, dateTimeConnect, '19700101'))), 105) +' '+ CONVERT(varchar(11), (DATEADD(hh, 2, DATEADD(s, dateTimeConnect, '19700101'))), 108)  AS start, FROM dbo.cdrdata

The output will look like this on my HTML (asp) page: 13-07-2010 (dd-mm-yyyy plus the stored TIME as well - the preferred dateformat in denmark).

My problem is that I'm not able to ORDER BY these dates since they are in some soft of CHAR format and not DATE format.

Is there another type of conversion where I get to keep the date format or is there another kind of order type where I get to list the dates ordered as dates?
Question by:jensjakobsen
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 39

Expert Comment

ID: 35069609
You can:
Do your order on SQL Server by your original field
convert them into a date datatype which can sort app side.
LVL 32

Accepted Solution

Ephraim Wangoya earned 500 total points
ID: 35069627

SELECT CONVERT(varchar(11), (DATEADD(hh, 2, DATEADD(s, dateTimeConnect, '19700101'))), 105) +' '+ CONVERT(varchar(11), (DATEADD(hh, 2, DATEADD(s, dateTimeConnect, '19700101'))), 108)  AS start,
FROM dbo.cdrdata
order by dateTimeConnect

Author Closing Comment

ID: 35107892
very precise

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PolyServe for SQL server 13 52
SQL server client app 3 75
SSIS - how to skip a step if it is spinning indefinitely in a step? 14 41
SQL Server how to create a DYNAMIC TABLE? 11 51
Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question ( here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question