简体   繁体   中英

Formatting a date value in Reporting Services

I am a bit rusty and would be very grateful if you could help. I am using Reporting Services. I am using T-SQL. The date_ordered field mentioned below is data type varchar.

I have a simple report that gives the date_ordered value. Unfortunately, when I ORDER BY date_ordered DESC, it sorts the date by the numerical value of the day, so 31-Oct-14 appears first and 01-Apr-13 last.

I would like the report to show most recent dates first and end with the last date ordered.

I'm sure it's very obvious, but I can't see it.

With many thanks.

you just have to convert your date to a datetime format in tsql. then when you sort it it works as expected.

Select CONVERT (datetime, '24-04-2012', 105 as date) as date, 
[date dispatched] from Orders order by 1

see How convert string to date T-SQL? and https://msdn.microsoft.com/en-us/library/ms187928.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM