Use DATENAME and wrap the logic in a Function, not a Stored Proc

declare @myTime as DateTime

set @myTime = GETDATE()

select @myTime

select DATENAME(day, @myTime) + SUBSTRING(UPPER(DATENAME(month, @myTime)), 0,4)

Returns "14OCT"

Try not to use any Character / String based operations if possible when working with dates. They are numerical (a float) and performance will suffer from those data type conversions.

Dig these handy conversions I have compiled over the years...

/* Common date functions */
--//This contains common date functions for MSSQL server

/*Getting Parts of a DateTime*/
    --//gets the date only, 20x faster than using Convert/Cast to varchar
    --//this has been especially useful for JOINS
    SELECT (CAST(FLOOR(CAST(GETDATE() as FLOAT)) AS DateTime))

    --//gets the time only (date portion is '1900-01-01' and is considered the "0 time" of dates in MSSQL, even with the datatype min value of 01/01/1753. 
    SELECT (GETDATE() - (CAST(FLOOR(CAST(GETDATE() as FLOAT)) AS DateTime)))


/*Relative Dates*/
--//These are all functions that will calculate a date relative to the current date and time
    /*Current Day*/
    --//now
    SELECT (GETDATE())

    --//midnight of today
    SELECT (DATEADD(ms,-4,(DATEADD(dd,DATEDIFF(dd,0,GETDATE()) + 1,0))))

    --//Current Hour
    SELECT DATEADD(hh,DATEPART(hh,GETDATE()),CAST(FLOOR(CAST(GETDATE() AS FLOAT)) as DateTime))

    --//Current Half-Hour - if its 9:36, this will show 9:30
    SELECT DATEADD(mi,((DATEDIFF(mi,(CAST(FLOOR(CAST(GETDATE() as FLOAT)) as DateTime)), GETDATE())) / 30) * 30,(CAST(FLOOR(CAST(GETDATE() as FLOAT)) as DateTime)))

    /*Yearly*/
    --//first datetime of the current year
    SELECT (DATEADD(yy,DATEDIFF(yy,0,GETDATE()),0))

    --//last datetime of the current year
    SELECT (DATEADD(ms,-4,(DATEADD(yy,DATEDIFF(yy,0,GETDATE()) + 1,0))))

    /*Monthly*/
    --//first datetime of current month
    SELECT (DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0))

    --//last datetime of the current month
    SELECT (DATEADD(ms,-4,DATEADD(mm,1,DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0))))

    --//first datetime of the previous month
    SELECT (DATEADD(mm,DATEDIFF(mm,0,GETDATE()) -1,0))

    --//last datetime of the previous month
    SELECT (DATEADD(ms, -4,DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0)))

    /*Weekly*/
    --//previous monday at 12AM
    SELECT (DATEADD(wk,DATEDIFF(wk,0,GETDATE()) -1 ,0))

    --//previous friday at 11:59:59 PM
    SELECT (DATEADD(ms,-4,DATEADD(dd,5,DATEADD(wk,DATEDIFF(wk,0,GETDATE()) -1 ,0))))

    /*Quarterly*/
    --//first datetime of current quarter
    SELECT (DATEADD(qq,DATEDIFF(qq,0,GETDATE()),0))

    --//last datetime of current quarter
    SELECT (DATEADD(ms,-4,DATEADD(qq,DATEDIFF(qq,0,GETDATE()) + 1,0)))
Answer from StingyJack on Stack Overflow
Top answer
1 of 10
27

Use DATENAME and wrap the logic in a Function, not a Stored Proc

declare @myTime as DateTime

set @myTime = GETDATE()

select @myTime

select DATENAME(day, @myTime) + SUBSTRING(UPPER(DATENAME(month, @myTime)), 0,4)

Returns "14OCT"

Try not to use any Character / String based operations if possible when working with dates. They are numerical (a float) and performance will suffer from those data type conversions.

Dig these handy conversions I have compiled over the years...

/* Common date functions */
--//This contains common date functions for MSSQL server

/*Getting Parts of a DateTime*/
    --//gets the date only, 20x faster than using Convert/Cast to varchar
    --//this has been especially useful for JOINS
    SELECT (CAST(FLOOR(CAST(GETDATE() as FLOAT)) AS DateTime))

    --//gets the time only (date portion is '1900-01-01' and is considered the "0 time" of dates in MSSQL, even with the datatype min value of 01/01/1753. 
    SELECT (GETDATE() - (CAST(FLOOR(CAST(GETDATE() as FLOAT)) AS DateTime)))


/*Relative Dates*/
--//These are all functions that will calculate a date relative to the current date and time
    /*Current Day*/
    --//now
    SELECT (GETDATE())

    --//midnight of today
    SELECT (DATEADD(ms,-4,(DATEADD(dd,DATEDIFF(dd,0,GETDATE()) + 1,0))))

    --//Current Hour
    SELECT DATEADD(hh,DATEPART(hh,GETDATE()),CAST(FLOOR(CAST(GETDATE() AS FLOAT)) as DateTime))

    --//Current Half-Hour - if its 9:36, this will show 9:30
    SELECT DATEADD(mi,((DATEDIFF(mi,(CAST(FLOOR(CAST(GETDATE() as FLOAT)) as DateTime)), GETDATE())) / 30) * 30,(CAST(FLOOR(CAST(GETDATE() as FLOAT)) as DateTime)))

    /*Yearly*/
    --//first datetime of the current year
    SELECT (DATEADD(yy,DATEDIFF(yy,0,GETDATE()),0))

    --//last datetime of the current year
    SELECT (DATEADD(ms,-4,(DATEADD(yy,DATEDIFF(yy,0,GETDATE()) + 1,0))))

    /*Monthly*/
    --//first datetime of current month
    SELECT (DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0))

    --//last datetime of the current month
    SELECT (DATEADD(ms,-4,DATEADD(mm,1,DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0))))

    --//first datetime of the previous month
    SELECT (DATEADD(mm,DATEDIFF(mm,0,GETDATE()) -1,0))

    --//last datetime of the previous month
    SELECT (DATEADD(ms, -4,DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0)))

    /*Weekly*/
    --//previous monday at 12AM
    SELECT (DATEADD(wk,DATEDIFF(wk,0,GETDATE()) -1 ,0))

    --//previous friday at 11:59:59 PM
    SELECT (DATEADD(ms,-4,DATEADD(dd,5,DATEADD(wk,DATEDIFF(wk,0,GETDATE()) -1 ,0))))

    /*Quarterly*/
    --//first datetime of current quarter
    SELECT (DATEADD(qq,DATEDIFF(qq,0,GETDATE()),0))

    --//last datetime of current quarter
    SELECT (DATEADD(ms,-4,DATEADD(qq,DATEDIFF(qq,0,GETDATE()) + 1,0)))
2 of 10
23

You can use the following command in SQL server to make it:

select FORMAT(getdate(), N'yyyy-MM-ddThh:mm:ss')
๐ŸŒ
SQLServerCentral
sqlservercentral.com โ€บ articles โ€บ dealing-with-custom-date-formats-in-t-sql
Dealing with custom date formats in T-SQL โ€“ SQLServerCentral
March 23, 2012 - Similarly, the PARSE function accepts a string parameter and does its best to convert it to various data types, including date and time subtypes. In this case, you are bound to using the recognized locales and cannot use a custom format, which is a shame in my opinion. For instance, you can use the PARSE function to convert the date used in the previous example: SELECT PARSE('24/10/2011' AS datetime USING 'it-IT') AS ItalianDate
Discussions

sql server convert date to string MM/DD/YYYY - Stack Overflow
I am using SQL Server 2008. I have the following: select convert(varchar(20),fmdate) from Sery How do I convert the date to string such that it show as MM/DD/YYYY More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to convert custom string to Date in SQL Server - Stack Overflow
Community Asks Sprint Announcement โ€“ January 2026: Custom site-specific badges! ... 233 Conversion failed when converting date and/or time from character string while inserting datetime ยท 0 How to convert MM/YYYY/DD format string to DATE in SQL Server? More on stackoverflow.com
๐ŸŒ stackoverflow.com
How do I format a date or convert a date to a specific string?
the default format for the dates in my database is MM/DD/YYYY (01/02/2021) Except it isn't. All date & time data types in SQL Server are stored as binary data, not as strings. They have no "format" - formatting is done by the client application (yes, even SSMS). When you enter a date like 01/02/2021 in an application, the application or SQL Server is making a guess about what you mean based on regional settings and possibly other factors. Unless you're storing your dates as strings. If you're doing that, we gotta have a chat. But like u/IHeartBadCode said, you really need a date table to do this kind of lookup/translation, not code embedded in a query. More on reddit.com
๐ŸŒ r/SQL
6
4
June 23, 2021
Powershell datetime insert to mysql
I assume just typing $dateformat returns the date looking as it should? What does the code that does the insert look like? Is it expecting a string or a DateTime object? You can see what you have with $dateformat.GetType(). If $dateformatis a string you can try casting it to DateTime by using this syntax: [DateTime]$dateformat=get-date $date -Format 'yyyy-MM-dd HH:mm' EDIT: Looks like u/xlrod just beat me to it :-) More on reddit.com
๐ŸŒ r/PowerShell
10
9
June 18, 2019
๐ŸŒ
Database Guide
database.guide โ€บ list-of-the-custom-date-time-format-strings-supported-by-the-format-function-in-sql-server
Custom Date/Time Format Strings Supported by FORMAT() in SQL Server
June 28, 2019 - The way custom format specifiers work, is that you can combine them together to form a custom format string when using the FORMAT() function. This determines how the result is formatted. ... DECLARE @date datetimeoffset; SET @date = '2080-05-01 23:09:08.1234567 +07:00'; SELECT FORMAT(@date, ...
๐ŸŒ
MSSQLTips
mssqltips.com โ€บ home โ€บ sql date format examples using convert function
SQL Date Format Examples using SQL CONVERT Function
September 26, 2025 - --SELECT a datetime column as a ... FROM Purchasing.PurchaseOrders WHERE OrderDate < @Datetime; Once the query runs, review SQL CONVERT output as shown below....
๐ŸŒ
W3Schools
w3schools.com โ€บ sql โ€บ func_sqlserver_convert.asp
SQL Server CONVERT() Function
String Functions: Asc Chr Concat with & CurDir Format InStr InstrRev LCase Left Len LTrim Mid Replace Right RTrim Space Split Str StrComp StrConv StrReverse Trim UCase Numeric Functions: Abs Atn Avg Cos Count Exp Fix Format Int Max Min Randomize Rnd Round Sgn Sqr Sum Val Date Functions: Date DateAdd DateDiff DatePart DateSerial DateValue Day Format Hour Minute Month MonthName Now Second Time TimeSerial TimeValue Weekday WeekdayName Year Other Functions: CurrentUser Environ IsDate IsNull IsNumeric SQL Quick Ref
๐ŸŒ
SQL Server Tutorial
sqlservertutorial.net โ€บ home โ€บ sql server system functions โ€บ convert datetime to string
Convert Datetime to String in a Specified Format in SQL Server
April 11, 2020 - DECLARE @dt DATETIME= '2019-12-31 14:43:35.863'; SELECT CONVERT(VARCHAR(10), @dt, 108) s1; Code language: SQL (Structured Query Language) (sql)
Find elsewhere
๐ŸŒ
Databasefaqs
databasefaqs.com โ€บ home โ€บ sql server convert datetime to string + examples
SQL Server Convert Datetime to String + Examples - DatabaseFAQs.com
March 23, 2023 - First, use the SQL Server Convert() function to change the DateTime expression to yyyymmdd string format.
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ sql โ€บ t-sql โ€บ functions โ€บ format-transact-sql
FORMAT (Transact-SQL) - SQL Server | Microsoft Learn
For general data type conversions, use CAST or CONVERT. ... Expression of a supported data type to format. For a list of valid types, see the table in the Remarks section. ... The format argument must contain a valid .NET Framework format string, either as a standard format string (for example, "C" or "D"), or as a pattern of custom characters for dates and numeric values (for example, "MMMM DD, yyyy (dddd)").
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ sql server โ€บ how-to-convert-datetime-to-varchar-in-sql-server
How to Convert DateTime to VarChar in SQL Server - GeeksforGeeks
July 23, 2025 - Two primary methods are commonly used for this conversion: the CONVERT() function and the FORMAT() function. ... The CONVERT() function in SQL Server allows the user to convert a DATETIME value to a string (VARCHAR) with a specific format.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ sql โ€บ sql-query-to-convert-datetime-to-string
SQL Query to Convert Datetime to String - GeeksforGeeks
July 23, 2025 - /*Declaring DATETIME as dt*/ DECLARE @dt DATETIME = (SELECT order_date FROM orders WHERE prod_id = 101); /*SELECT statement is used to print the s1 message*/ SELECT CONVERT(VARCHAR(20),@dt,0) s1;
๐ŸŒ
DotFactory
dofactory.com โ€บ sql โ€บ convert-datetime-to-string
SQL Convert DATETIME to String
The CONVERT function can convert datetime to string values. Optionally, the date format can be specified with a style argument (see below for options).
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ sql-convert-the-date-to-string-or-datetime-function-2
SQL CONVERT โ€“ The DATE to String or DATETIME Function
January 10, 2023 - If you want the month as the full name of that month, change the m in the format to a capital letter and use the DATE_FORMAT() function: ... This article showed you how to convert a date to a string with the CONVERT() and STR_TO_DATE() functions.
๐ŸŒ
SQL Server Guides
sqlserverguides.com โ€บ how-to-convert-date-to-string-in-sql-server
How To Convert Date To String In SQL Server - SQL Server Guides
June 21, 2025 - For those using SQL Server 2012 or newer versions, the FORMAT() function offers a more flexible way to format dates as strings. ... The FORMAT() function uses the following patterns.
๐ŸŒ
SQL Shack
sqlshack.com โ€บ sql-server-functions-for-converting-string-to-date
SQL Server functions for converting a String to a Date
May 21, 2021 - In this article, we will learn about SQL Server convert String to Date functions like CAST(), TRY_CAST(), CONVERT(), TRY_CONVERT() and TRY_PARSE() to convert a string to a date format in SQL Server.
๐ŸŒ
SQLines
sqlines.com โ€บ sql-server-to-postgresql โ€บ convert_string_datetime
CONVERT - Datetime to String - SQL Server to PostgreSQL Migration - SQLines Tools
In SQL Server, you can use the CONVERT function to convert a DATETIME value to a string with the specified format. In PostgreSQL, you can use the TO_CHAR function. Note that SQL Server CONVERT and PostgreSQL TO_CHAR formats are different. SQL Server: