Supported by SQL Server 2005 and later versions

SELECT CONVERT(VARCHAR(10), GETDATE(), 101) 
       + ' ' + CONVERT(VARCHAR(8), GETDATE(), 108)

* See Microsoft's documentation to understand what the 101 and 108 style codes above mean.

Supported by SQL Server 2012 and later versions

SELECT FORMAT(GETDATE() , 'MM/dd/yyyy HH:mm:ss')

Result

Both of the above methods will return:

10/16/2013 17:00:20
Answer from M.Ali on Stack Overflow
๐ŸŒ
SQL Shack
sqlshack.com โ€บ sql-convert-date-functions-and-formats
SQL Convert Date functions and formats
May 21, 2021 - Suppose you have data in a table in the format YYYY-MM-DD hh:mm: ss. You have a daily Sales report, and in that, you want data group by date.
Discussions

Date Format (mm/dd/yyyy hh:mm), no seconds or milliseconds โ€“ SQLServerCentral Forums
Date Format (mm/dd/yyyy hh:mm), no seconds or milliseconds Forum โ€“ Learn more on SQLServerCentral More on sqlservercentral.com
๐ŸŒ sqlservercentral.com
February 9, 2009
Datetime conversion Format dd/mm/yyyy hh:mm:ss AM - SQL Server Forums
Microsoft SQL Server articles, forums and blogs for database administrators (DBA) and developers. More on sqlteam.com
๐ŸŒ sqlteam.com
March 11, 2011
sql - Format date as yyyy-mm-dd hh:mm:ss.000 - Stack Overflow
I have this date: 7/19/2013 I want to format it as the following: 2013-07-19 00:00:00.000 I tried this: select convert(varchar(10),'7/19/2013',120) But it is giving me the same result! More on stackoverflow.com
๐ŸŒ stackoverflow.com
Date and time format not recognized (MMM DD, YYYY, HH:MM:SS AM/PM)
u/xing111111 - Your post was submitted successfully. Once your problem is solved, reply to the answer(s) saying Solution Verified to close the thread. Follow the submission rules -- particularly 1 and 2. To fix the body, click edit. To fix your title, delete and re-post. Include your Excel version and all other relevant information Failing to follow these steps may result in your post being removed without warning. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
๐ŸŒ r/excel
5
3
December 6, 2023
๐ŸŒ
Microsoft
social.msdn.microsoft.com โ€บ Forums โ€บ en-US โ€บ b0363043-68ac-4dd3-833d-a8b225abceee โ€บ how-to-convert-date-to-mmddyyyy-hhmmss-am-pm
How to convert Date to mm/dd/yyyy hh:mm:ss: AM PM | Microsoft Learn
April 19, 2012 - Hello John, Please check the following page for SQL date time convert options What I see there is using the option 22 for your requirement as you said declare @t datetime = '11/30/2012 04:10:41 PM' select convert(varchar(50),@t,22) Returns "11/30/12 4:10:41 PM" You only need to change year part from 12 to 2012
๐ŸŒ
Sybase
infocenter.sybase.com โ€บ help โ€บ topic โ€บ com.sybase.infocenter.dc32300.1570 โ€บ html โ€บ sqlug โ€บ BABDBAHF.htm
Changing the date format
The default value is 100 (mon dd yyyy hh:miAM (or PM )). If date data is converted to a style that contains a time portion, that time portion reflects the default value of zero.When converting time data to a character type, use style number 8 or 9 (108 or 109) to specify the display format.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ setup-the-format-of-datetime-to-ddmm-yyyy-hh-mm-ss-with-mysql-select
Setup the format of DATETIME to 'DDMM- YYYY HH:MM:SS' with MySQL SELECT?
Whenever you retrieve datetime from a table, the datetime gives โ€˜YYYY-MM-DDโ€™ format. If you want to change the output, then you need to use in-built date_format() from MySQL. The syntax is as follows โˆ’
Find elsewhere
๐ŸŒ
Sqlinfo
sqlinfo.net โ€บ sqlserver โ€บ sql_server_SELECT-Formatting_Date_Time.php
sqlinfo.net - sqlinfo Resources and Information.
sqlinfo.net is your first and best source for all of the information youโ€™re looking for. From general topics to more of what you would expect to find here, sqlinfo.net has it all. We hope you find what you are searching for!
๐ŸŒ
SQL Team
sqlteam.com โ€บ forums โ€บ topic.asp
Datetime conversion Format dd/mm/yyyy hh:mm:ss AM - SQL Server Forums
March 11, 2011 - Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
๐ŸŒ
SQLServerCentral
sqlservercentral.com โ€บ Forums โ€บ Topic1495955-391-1.aspx
Convert date to a format of dd/mm/yyyy HH:mm:ss โ€“ SQLServerCentral ...
September 18, 2013 - Convert date to a format of dd/mm/yyyy HH:mm:ss Forum โ€“ Learn more on SQLServerCentral
๐ŸŒ
W3Schools
w3schools.com โ€บ sql โ€บ func_sqlserver_convert.asp
SQL Server CONVERT() Function
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.
Top answer
1 of 4
16

You need to tell SQL Server it's a date; otherwise, it just sees a string, and ignores the style number since it's not relevant for a string. As Steve Kass pointed out, the code is only truly portable if you protect the incoming string from incorrect regional- or language-based translations (such as d/m/y - which could lead to an error or, even worse, the wrong data). I've updated the code to interpret the string as m/d/y regardless of locale, but if you're on SQL Server 2012 you could also use PARSE() as in his example (or TRY_PARSE() if you want to essentially ignore invalid dates).

And if you want the time attached including milliseconds, you need to allow more than 10 characters, and a style that supports milliseconds.

SELECT CONVERT(CHAR(23),CONVERT(DATETIME,'7/19/2013',101),121);

Result:

2013-07-19 00:00:00.000

If you don't care about milliseconds, you can use style 120 instead:

SELECT CONVERT(CHAR(19),CONVERT(DATETIME,'7/19/2013',101),120);

And if you don't care about seconds, you can truncate earlier:

SELECT CONVERT(CHAR(16),CONVERT(DATETIME,'7/19/2013',101),120);
2 of 4
4

Note that Aaron's solution will fail if the server is localized to a language with DMY as the date format. This is because the inner CONVERT in Aaron's example will incorporate the server locale, which may not be what you expect.

To make this bulletproof (assuming the source of the string doesn't automatically re-localize the format), convert the string with PARSE (requires SQL Server 2012 or later).

SET LANGUAGE English
SELECT CONVERT(CHAR(23),TRY_CONVERT(DATETIME,'7/19/2013'),121);
SELECT CONVERT(CHAR(23),PARSE('7/19/2013' AS DATETIME USING 'en-US'),121);

SET LANGUAGE Franรงais
SELECT CONVERT(CHAR(23),TRY_CONVERT(DATETIME,'7/19/2013'),121);
SELECT CONVERT(CHAR(23),PARSE('7/19/2013' AS DATETIME USING 'en-US'),121);
๐ŸŒ
MSSQLTips
mssqltips.com โ€บ home โ€บ format sql server dates with format function
Format SQL Server Dates with FORMAT Function
October 31, 2025 - Can you update your second date sample? SELECT FORMAT (getdate(), โ€˜dd/MM/yyyy, hh:mm:ss โ€˜) as date for 2 PM would return 02:00:00.
๐ŸŒ
Folkstalk
folkstalk.com โ€บ home โ€บ 2022 โ€บ september
Sql Server Date Format Yyyy-Mm-Dd With Code Examples
September 21, 2022 - SQL Date Data Types DATE โ€“ format YYYY-MM-DD. DATETIME โ€“ format: YYYY-MM-DD HH:MI:SS. TIMESTAMP โ€“ format: YYYY-MM-DD HH:MI:SS.