Solved

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

Posted on 2011-03-08
3
305 Views
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?
0
Comment
Question by:jensjakobsen
3 Comments
 
LVL 39

Expert Comment

by:BrandonGalderisi
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.
0
 
LVL 32

Accepted Solution

by:
ewangoya 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
0
 
LVL 1

Author Closing Comment

by:jensjakobsen
ID: 35107892
very precise
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 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