问题
What is the format to be used in SQL to get date in format like
dd/mm/yyyy hr:mm:ss AM/PM
eg: 9/17/2013 4:55:43 PM
The link below gives an answer but i want value in seconds also
How to display Date in DD/MM/YYYY H:MM AM/PM format in SQL Server
Instead of 101 in below query.
convert(varchar, CONVERT(smalldatetime, PhaseStartDate), 101)
回答1:
You can check both posts below... They convert to mm/dd instead of dd/mm
but to get what you want, just change to 103 instead of 101 ;)
Link 1 Link 2
回答2:
select convert(varchar(10), GETDATE(), 103 /*or 101*/) + ' ' +
ltrim(right(convert(varchar(20), GETDATE(), 22), 11))
回答3:
Probably you meant 103 or mm/dd/yyyy instead. You could craft that yourself from the pieces or combine and craft from two or more styles.
IMHO, that should be something you do in your front end.
回答4:
CONVERT(VARCHAR(10), PhaseStartDate, 101) + Substring((CONVERT(VARCHAR(20), PhaseStartDate, 22)),9,12) as PhaseStartDate
Useful Link is here http://www.sql-server-helper.com/sql-server-2008/sql-server-2008-date-format.aspx
回答5:
I assume that you're not using SQL Server 2005. here is your query
SELECT
CONVERT(VARCHAR,GETDATE(),103) +' '+
CONVERT(VARCHAR(8),CAST( GETDATE() AS TIME ))+' '+
SUBSTRING(CONVERT(VARCHAR(30), GETDATE(), 9), 25, 2)
来源:https://stackoverflow.com/questions/33412863/date-format-in-sql-dd-mm-yyyy-hrmmss-am-pm