Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Date Formatting


Date Formatting

Author
Message
jsheikabdullah
jsheikabdullah
SSC Journeyman
SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)

Group: General Forum Members
Points: 92 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?
LutzM
LutzM
SSCertifiable
SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)

Group: General Forum Members
Points: 7021 Visits: 13559
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
jsheikabdullah
jsheikabdullah
SSC Journeyman
SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)

Group: General Forum Members
Points: 92 Visits: 36
In the front end can u tell me the logic how to do it
LutzM
LutzM
SSCertifiable
SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)

Group: General Forum Members
Points: 7021 Visits: 13559
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
jsheikabdullah
jsheikabdullah
SSC Journeyman
SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)

Group: General Forum Members
Points: 92 Visits: 36
In vb.net
arun.sas
arun.sas
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1237 Visits: 3493
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))


jsheikabdullah
jsheikabdullah
SSC Journeyman
SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)

Group: General Forum Members
Points: 92 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.
HowardW
HowardW
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1211 Visits: 9892
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search