May 21, 2010 at 10:14 am
http://www.tek-tips.com/faqs.cfm?fid=4191
How to call that function, give me the sql.
May 21, 2010 at 10:25 am
First you have to create the function in your database, then you would put the function in the SELECT clause of your query with the datetime column/variable/parameter and one of the format types handled by the function. So it would look something like this:
Select fn_formatdatetime (getdate(), 'm/d/yy')
I'll add one caveat, scalar UDF's like this kill performance. You would be much better off handling formatting in the UI.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
May 21, 2010 at 10:26 am
it's fairly simply, just pass in the format string you want to use; if you are familiar with the CONVERT(date,StyleNumber), many of the typical formats are built in:
declare @TheDate datetime
SET @TheDate = getdate()
--it's simply
SELECT dbo.fn_formatdatetime (@TheDate ,'YYYY-MM-DD')
Lowell
May 21, 2010 at 10:40 am
Thanx guys
but how to mark as answered so you get points in the forum.
May 21, 2010 at 10:43 am
just the "thank you" you already gave us is enough; we all apreciate receiving that!
Lowell
May 21, 2010 at 10:43 am
I'll add one caveat, scalar UDF's like this kill performance. You would be much better off handling formatting in the UI.
what you mean, do u mean that the fun is too big?
May 21, 2010 at 12:59 pm
No I don't mean the function is too big, I mean that the UDF will have to be called for every row in the dataset and, depending on what it does it could cause problems. That one isn't too bad because it doesn't access another table. Just don't use it on a column in the where clause.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply