Date/Time formatting trick for SQL Server
As we all know, ColdFusion has a stellar line up of date and time formatting functions. But what happens when you need to do this at the database query level in a CFC or a Stored Procedure? Plus a FREE Scalar function!
So here's a quick way using SQL Server's CONVERT function to produce a MM/DD/YYYY HH:MM AM type of format (example output: 05/10/2010 03:17 PM) directly in your SELECT statement...
2 CONVERT(VARCHAR(10), a.EntryDate, 101) + ' ' + REPLACE(REPLACE(RIGHT('0'+LTRIM(RIGHT(CONVERT(VARCHAR,a.EntryDateTime,100),7)),7),'AM',' AM'),'PM',' PM') AS EntryDateTimeDisplay,
3FROM MyTableName
This can prove to be useful if you want to handle the date and time formatting within a cfquery or maybe even inside of a T-SQL Stored Procedure that you'll call via ColdFusion. If you want to get downright modular and really fancy (and who doesn't?) then you could create your own SCALAR function in SQL Server and just call it inline directly in a SELECT statement. Here, just run this from a T-SQL prompt and you too can call it right from your very own cfquery! (Don't say I never gave you anything ;)
2RETURNS VARCHAR(30)
3AS
4BEGIN
5 DECLARE @newDateTimeString VARCHAR(30)
6 SET @newDateTimeString = CONVERT(VARCHAR(10), @dateTimeData, 101) + ' ' + REPLACE(REPLACE(RIGHT('0'+LTRIM(RIGHT(CONVERT(VARCHAR,@dateTimeData,100),7)),7),'AM',' AM'),'PM',' PM')
7 RETURN @newDateTimeString
8END
So now that we've done the heavy lifting up front we can use this in any query just as if it were an out of the box SQL Server function - which means that you can also use it all over the place in ColdFusion cfquery statements too - WOOT!
2 dbo.formatDateTime(GETDATE()) AS CurrentDateTimeDisplay
Remember folks, FUNCTIONS are your friends!

" rel="nofollow"> Ciphone </a>. d^_^bIt is very interesting.I want to introduce <a href="http://www.efox-shop.com/" rel="nofollow"> efox-shop</a> to you.
http://www.nfljerseyspaypal.com cheap nfl jerseys
http://www.nfljerseysgo.com NFL Shop
http://www.nfljerseysgo.com NFL Jerseys
http://www.eightshop.com polo shirts
http://www.onesunglasses.com oakley sunglasses
http://www.onesunglasses.com ray ban sunglasses
http://www.onesunglasses.com gucci sunglasses