Click here to Skip to main content
11,477,625 members (77,981 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-Server-2008
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
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 4-Mar-13 16:56pm
N@veen.S1.6K
Edited 4-Mar-13 17:01pm
v2
Comments
gvprabu at 6-Mar-13 22:01pm
   
Hi Naveen,
Check my post... its useful to you or not? :-)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

My self to resolve this issue...

Using this
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..
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hi....

Its very simple ... try this Smile | :) Smile | :) Smile | :)
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
  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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))
  Permalink  
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 274
1 Richard Deeming 245
2 _duDE_ 165
3 Tomas Takac 150
4 Sascha Lefèvre 145
0 Sergey Alexandrovich Kryukov 7,675
1 OriginalGriff 7,246
2 Sascha Lefèvre 3,034
3 Maciej Los 2,491
4 Richard Deeming 2,305


Advertise | Privacy | Mobile
Web04 | 2.8.150520.1 | Last Updated 4 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100