How to get a particular date format ('dd-MMM-yyyy') in SELECT query SQL Server 2008 R2
Try this:
Declare @dt NVARCHAR(20)
Select
@dt = REPLACE(CONVERT(CHAR(15), SalesDate, 106),' ',' - ')
FROM SalesTable
Convert Date format into DD/MMM/YYYY format in SQL Server
I'm not sure there is an exact match for the format you want. But you can get close with convert()
and style 106
. Then, replace the spaces:
SELECT replace(convert(NVARCHAR, getdate(), 106), ' ', '/')
How to convert a string to a date from dd mmm yyyy format in SQL Server
You can use the following using CONVERT
:
SELECT CONVERT(DATE, string, 106)
-- example
SELECT CONVERT(DATE, '07 Nov 2014', 106) -- 2014-11-07
You can find a list with all date and time styles (3rd parameter - 106
) on the microsoft docs. You can also find a working demo on SQL Fiddle.
date format convert into varchar dd-mmm-yy format in sql server 2012
Try with the below query..
DECLARE @testdate DATETIME
SELECT @testdate = '2016-08-23'
SELECT LEFT (CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(@testdate)-1),@testdate),113),6)
+' to '+LEFT(CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(DATEADD(mm,1,@testdate))),
DATEADD(mm,1,@testdate)),113),11) AS Date_Value
Related Topics
How to Declare Global Variable in SQL Server..
Postgres Analogue to Cross Apply in SQL Server
Join Comma Delimited Data Column
How to Delete from Multiple Tables in the Same SQL Statement
What's the Proper Index for Querying Structures in Arrays in Postgres JSONb
What Does Sp_Reset_Connection Do
How to Interpret Precision and Scale of a Number in a Database
Use Email Address as Primary Key
Storing Sex (Gender) in Database
Does Ms SQL Server's "Between" Include the Range Boundaries
SQL Server Ignore Case in a Where Expression
Extract Date (Yyyy/Mm/Dd) from a Timestamp in Postgresql
How Can a Left Outer Join Return More Records Than Exist in the Left Table
How to Check Which Locks Are Held on a Table
Creating Temporary Tables in SQL
What Happens to an Uncommitted Transaction When the Connection Is Closed