Click here to Skip to main content
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 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 OriginalGriff 120
3 PIEBALDconsult 110
4 Zoltán Zörgő 99
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,342


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 4 Mar 2013
Copyright © CodeProject, 1999-2014
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