Click here to Skip to main content
15,906,558 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to get the month with two digit from given string variable in SQL Server 2008.

Ex:Declare @date varchar(50)
set @date='15/02/2012'

I need output only
--------
02
Posted
Updated 6-Mar-12 0:29am
v2

use DatePart function
SQL
SELECT DATEPART(yyyy,OrderDate) AS OrderYear,
DATEPART(mm,OrderDate) AS OrderMonth,
DATEPART(dd,OrderDate) AS OrderDay,
FROM Orders
WHERE OrderId=1
 
Share this answer
 
Try With This

SQL
Declare @date varchar(50)
set @date=cast(month('15-Feb-2012') as nvarchar(50))
Select @Date
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900