This UDF will take a datetime variable and a varchar format string variable. It will then pass back the date/time formated according to the format string. This is similar to the CONVERT function, but you are not limited to the predefined types of it. It works more like the Format function of...
Ok... Another bug correction...
'm/d/yy h:nnam/pm' would replace the 'm's in 'am/pm' with the month, then the 'am/pm' conversion wouldn't work... So, if you would like to try the function, here is the whole thing... Let me know if anybody has any problems. (I dropped the comment section at the...
Ok... using what clarkin explained... the nested IF block at the bottom can be changed to...
IF CHARINDEX('m',@outStr,0) > 0 BEGIN
IF CHARINDEX('mm',@outStr,0) > 0 BEGIN
IF CHARINDEX('mmm',@outStr,0) > 0 BEGIN
IF CHARINDEX('mmmm',@outStr,0) > 0 BEGIN
SET @outStr = REPLACE(@outStr...
Thanks! I looked for something like INSTR in the String Functions in my SQL Help but couldn't find anything like it. That helps a lot!
The CONVERT functin does provide several different formats but none of them quite matched the format I needed which is the reason for the format function...
In Access and Visual Basic this is a nice little "Format" function you can pass a date/time variable and a formating string and it returns the combined result. Like Format(Now(), "m/d/yy") Would return a string like "1/2/03". This function does not exist in SQL...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.