February 16, 2018 at 3:16 am
Hi
I have a datetime field called Election date, defined as follows:
DECLARE @ElectionDate datetime = '09/10/2018 11:00:01'
How do i format this so its shown as 'Oct 9 2018' ?
February 16, 2018 at 4:29 am
Use the CONVERT function:
This will do exactly what you asked for...
SELECT CONVERT(CHAR(11),GETDATE(),100);
This will add the typical comma before the year
SELECT CONVERT(CHAR(12),GETDATE(),107);
For more information on the CONVERT function, please see the following link...
https://docs.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql
If someone suggests the use of the "new" FORMAT function, remind them that it takes 44 times longer to execute than CONVERT does and that code portability is a myth. 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply