Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Date Formatting Expand / Collapse
Author
Message
Posted Monday, September 14, 2009 12:54 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, February 2, 2012 5:18 AM
Points: 91, Visits: 36
I want to get a date in the following format ex- 14-09-2009 should be returned in the format 14th September 2009. Can nay one tell me how?
Post #787198
Posted Monday, September 14, 2009 1:13 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 4:28 PM
Points: 6,853, Visits: 13,405
Where do you want to convert the date format - SSRS or Database?
If the latter I strongly recommend against it. Date formatting should be done at the front end side (e.g. SSRS), especially, if the target format cannot be achieved using the standard CONVERT function.
In the scenario you described a concatenation of various CONVERT functions together with DATENAME function would be required.




Lutz
A pessimist is an optimist with experience.

How to get fast answers to your question
How to post performance related questions
Links for Tally Table , Cross Tabs and Dynamic Cross Tabs , Delimited Split Function
Post #787202
Posted Monday, September 14, 2009 1:42 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, February 2, 2012 5:18 AM
Points: 91, Visits: 36
In the front end can u tell me the logic how to do it
Post #787216
Posted Monday, September 14, 2009 2:09 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 4:28 PM
Points: 6,853, Visits: 13,405
jsheikabdullah (9/14/2009)
In the front end can u tell me the logic how to do it


For what type of front end?




Lutz
A pessimist is an optimist with experience.

How to get fast answers to your question
How to post performance related questions
Links for Tally Table , Cross Tabs and Dynamic Cross Tabs , Delimited Split Function
Post #787232
Posted Monday, September 14, 2009 2:17 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, February 2, 2012 5:18 AM
Points: 91, Visits: 36
In vb.net
Post #787237
Posted Monday, September 14, 2009 2:18 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, April 19, 2012 10:25 PM
Points: 1,229, Visits: 3,483
Hi,
try this
Declare @RESULT datetime
set @RESULT = getdate()
--
select (cast(day(@RESULT) as varchar)+
(case when (right(day(@RESULT),1) >= 4)
or(right(day(@RESULT),1)= 0)
or((left(day(@RESULT),1) = 1)and len(day(@RESULT))= 2) then 'th'
when right(day(@RESULT),1) = 1 then 'st'
when right(day(@RESULT),1) = 2 then 'nd'
when right(day(@RESULT),1) = 3 then 'rd'
end)+
space(1)+
datename(mm,@RESULT)+
space(1)+
cast(year(@RESULT) as varchar))

Post #787238
Posted Monday, September 14, 2009 2:41 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, February 2, 2012 5:18 AM
Points: 91, Visits: 36
thanks it worked but shocking to know that the date format which is almost used in all forums for displaying is not supported by default in SQL.
Post #787246
Posted Monday, September 14, 2009 3:41 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, November 3, 2014 8:05 AM
Points: 1,191, Visits: 9,892
Well the point is that SQL Server is the back-end and nicely formatting things is the job of the front-end. It's just not what SQL was designed for.

It's also beneficial in other ways to pass the data to the front end as the proper type (a date) rather than a string so you can re-sort it efficiently from the client end.

If you're using VB.net, it's pretty straight forward, example below:

Dim idate As Date
idate = "2009-01-01"
MsgBox(idate.ToString("dd MMMM yyyy"))

Adding the "th", "rd" etc isn't natively supported as far as I'm aware, but there are plenty of examples for building a vb.net function to do this on the web
Post #787273
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse