Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a Month & year , using that i want to display total date with day is -01 and time is 0's.

How to achieve this

ex:

month -3

year-2013

i want to display this is first day of march like '2013-03-01 00:00:00'

i'm using something like this but this is not given exact result
SQL
cast(year(release_date) as char(5))+'-'+cast(month(release_date) as char(2))+'-'+'01 00:00:00'


using this month returns 3, so the result becomes like this 2013-3-01 00:00:00, but this is not in correct format na.....
Posted
Updated 4-Mar-13 16:01pm
v2
Comments
gvprabu 6-Mar-13 22:01pm    
Hi Naveen,
Check my post... its useful to you or not? :-)

My self to resolve this issue...

Using this
SQL
convert (datetime ,cast(year(release_date) as varchar(4))+right('00'+cast(month(release_date) as varchar(2)),2)+right('00' + cast(@day as varchar(2)),2)) AS Release_Date


It might be helpfull to some other , who are confusing about the same issue..
 
Share this answer
 
Hi....

Its very simple ... try this :-) :-) :-)
SQL
DECLARE @CurDate DATETIME=GETDATE()
 
SELECT CONVERT(DATETIME,CAST(YEAR(@CurDate) AS VARCHAR(5))+'-'+CAST(MONTH(@CurDate)AS VARCHAR(5))+'-01',101) 'ReqDate'

ReqDate
----------------------
2013-03-01 00:00:00.000
 
Share this answer
 
v3
Check this:


SELECT CAST(YEAR(GETDATE())AS VARCHAR(4))+'-'+ CAST( MONTH(GETDATE())AS VARCHAR(4))+'-'+ CAST(01 AS VARCHAR(2))+' '+CAST('00:00:00' AS VARCHAR(10))
 
Share this answer
 
v2

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