September 10, 2007 at 3:40 am
Hi All,
How to find the Last date of Previous month.
for Example,
if you are giving getdate() as the value it should give the output as 31-Aug-2007.
Can you please help me on this.
Regards,
Ezhilan
September 10, 2007 at 3:53 am
DECLARE @D datetime
SELECT @D = GETDATE()
SELECT DATEADD(day, - DAY(@D), @D)
September 10, 2007 at 4:14 am
Thanks it is working fine..
I have used..this..
select convert(datetime,convert(char,getdate()-datepart(dd,getdate()),103),104)
Is it OK.
Regards,
Ezhilan
September 10, 2007 at 4:42 am
SELECT
DATEADD(MONTH, DATEDIFF(MONTH, 0, CURRENT_TIMESTAMP), -1)
N 56°04'39.16"
E 12°55'05.25"
September 10, 2007 at 7:18 am
Ezhilan, is there a reason for the two converts in your statement? They seem superfluous to me, as you are converting back into a datetime in the end, so the style codes aren't going to actually take affect. Additionally, you have two different style codes in the first place.
I'd recommend you go with either Koji's or Peter's recommendations. Both should work fine, and Peter's method (zero-based date functions) is the one that is currently gaining in popularity. While it doesn't exhibit itself in this particular situation, that method can make for some very elegant (read short and concise) date manipulation in many cases.
September 10, 2007 at 11:02 pm
Thanks David...
September 11, 2007 at 12:44 am
For more versatile uses of DATEADD/DATEDIFF combinations, see
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=86769
N 56°04'39.16"
E 12°55'05.25"
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply