In SQL server, date is getting saved in the following format:-
2017-02-20 05:59:58.537
But I need the output in the following format:
20/Feb/2017 11:29:58 AM
In SQL server, date is getting saved in the following format:-
2017-02-20 05:59:58.537
But I need the output in the following format:
20/Feb/2017 11:29:58 AM
Try This
select replace(convert(varchar(11),GETDATE(),113), ' ', '/')+ ' '+ RIGHT(CONVERT(varchar(20), GETDATE(), 22), 11);
Try this,
SELECT replace(convert(NVARCHAR, getdate(), 106), ' ', '/')+' '+right(getdate(),7)
Try below conversion method :
DECLARE @DATE DATETIME = '2017-02-20 05:59:58.537'
SELECT REPLACE(CONVERT(VARCHAR(11),@DATE,113), ' ', '/') + ' '
+CONVERT(VARCHAR(20),@DATE,108)+' ' +RIGHT(@DATE,2)
SQL stores the date as per the default setting (yyyy-mm-dd hh:mm:ss:ms). while fetching that date you need to convert that date according to your requirement.
I have a date Function I use, and you could modify it to include details for hours, minutes and seconds, too.
CREATE FUNCTION [dbo].[fn_DateDisplay]
(
-- Add the parameters for the function here
@dateIn date
)
RETURNS nvarchar(MAX)
AS
BEGIN
-- Declare the return variable here
DECLARE @dateOut nvarchar(MAX)
DECLARE @yearIn int
DECLARE @monthIn int
DECLARE @dayIn int
DECLARE @monthOut nvarchar(3)
-- Add the T-SQL statements to compute the return value here
SET @yearIn = YEAR ( @dateIn )
SET @monthIn = MONTH ( @dateIn )
SET @dayIn = DAY ( @dateIn )
SET @monthOut = SUBSTRING ( DATENAME ( MONTH , @dateIn ) , 1 , 3 )
SET @dateOut = CONCAT ( @dayIn , ' ' , @monthOut , ' ' , @yearIn )
-- Return the result of the function
RETURN @dateOut
END