What is wrong in sql
CONCAT(title, ', from ', CONVERT(DATETIME,CONVERT(NVARCHAR,startdate,107)), ' to ', CONVERT(DATETIME,CONVERT(NVARCHAR,end_date,107)), ' (', duration , ')')
I want to change datetime to Sep 25, 2018 format
What is wrong in sql
CONCAT(title, ', from ', CONVERT(DATETIME,CONVERT(NVARCHAR,startdate,107)), ' to ', CONVERT(DATETIME,CONVERT(NVARCHAR,end_date,107)), ' (', duration , ')')
I want to change datetime to Sep 25, 2018 format
SELECT LEFT(DATENAME(MONTH, GETDATE()), 3) + ' ' + cast(datepart(dd, getdate()) as varchar) + ', ' + cast(datepart(yyyy, getdate()) as varchar)
or
select convert(nvarchar,getdate(),107)
The question is somewhat unclear, I think your issue lies in that you are converting the date to an nvarchar using the 107 format which is correct for what you posted you wish to do. You then convert it back to a datetime, which reverts it back to the default settings for the date.
So I think you just need to simplify it to:
CONCAT(title, ', from ',CONVERT(NVARCHAR,startdate,107), ' to ',CONVERT(NVARCHAR,end_date,107), ' (', duration , ')')
Original:
select convert(datetime,convert(nvarchar,getdate(),107));
Returns (this is based on local settings, so for the SQL Server I used, it returns this):
2018-08-30 00:00:00.000
Less Conversion Code:
select convert(nvarchar,getdate(),107);
Returns:
Aug 30, 2018