I have a element of my SQL Query which is outputting a date,
Query Element
CONVERT(DATETIME, CONVERT(CHAR(8), UPOST, 100)) AS UPDATED
Output
2013-05-03 00:00:00.000
What I need to do is get rid of the zeros and change the format so that it reads like this;
03-05-2013
Can anyone suggest a way to do this
CONVERT(VARCHAR(113), CONVERT(DATETIME, CONVERT(CHAR(8), UPOST, 100)), 105) AS UPDATED
最后的105表示格式为dd-mm-yyyy
We have something like this function:
CREATE FUNCTION fn_StripTime(@DT datetime)
RETURNS datetime
AS
BEGIN
return convert(datetime, convert(nvarchar,@DT,112))
END
Use 110
instead of 100
CONVERT(VARCHAR(10), GETDATE(), 110) AS UPDATED
110
will format the date as MM-DD-YYYY
And, for future reference, bookmark this page: http://www.sql-server-helper.com/tips/date-formats.aspx
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.