Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2002
    Location
    Berlin
    Posts
    72

    Question Unanswered: Date calculation

    Hi,

    I am simply looking for a calculation to get back always the last day of the month. Can anybody help me ?

  2. #2
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401

    Re: Date calculation

    Originally posted by dajm
    Hi,

    I am simply looking for a calculation to get back always the last day of the month. Can anybody help me ?
    Code:
    declare @month int,
    	@year int
    select @month = 2,
    	@year = 2000
    select dateadd(dd,-1,convert(datetime,convert(varchar,(@month+1))+ '/01/'+convert(varchar,@year)))
    I assume you must be passing the year & month to get the last day of the month. The above will work for that
    Get yourself a copy of the The Holy Book

    order has no physical Brett in The meaning of a Kaiser . -database data

  3. #3
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Must'nt forget about december

    Code:
    DECLARE @x datetime
    SELECT @x = GetDate()
    SELECT DATEADD(mm,1,CONVERT(datetime,CONVERT(varchar(2),DATEPART(mm,@x))+'/01/'+CONVERT(varchar(4),DATEPART(yy,@x))))-1
    What happens with this?

    Code:
    declare @month int,
    	@year int
    select @month = 12,
    	@year = 2000
    select dateadd(dd,-1,convert(datetime,convert(varchar,(@month+1))+ '/01/'+convert(varchar,@year)))
    ???????
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  4. #4
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    Good point brett !!!
    My Bad
    Get yourself a copy of the The Holy Book

    order has no physical Brett in The meaning of a Kaiser . -database data

  5. #5
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    I dont seem to unserstand .. why all my posts are being posted in the duplicate today ???? i mean for every post i am making ... its being submitted twice
    Last edited by Enigma; 12-01-03 at 16:33.
    Get yourself a copy of the The Holy Book

    order has no physical Brett in The meaning of a Kaiser . -database data

  6. #6
    Join Date
    Jan 2002
    Location
    Berlin
    Posts
    72
    Originally posted by Brett Kaiser
    Must'nt forget about december

    Code:
    DECLARE @x datetime
    SELECT @x = GetDate()
    SELECT DATEADD(mm,1,CONVERT(datetime,CONVERT(varchar(2),DATEPART(mm,@x))+'/01/'+CONVERT(varchar(4),DATEPART(yy,@x))))-1
    What happens with this?

    Code:
    declare @month int,
    	@year int
    select @month = 12,
    	@year = 2000
    select dateadd(dd,-1,convert(datetime,convert(varchar,(@month+1))+ '/01/'+convert(varchar,@year)))
    ???????
    Sorry Brett, your function gives me back the same day of the last month. I am searching for something following: today is 2003/12/02 and what I need the get returned is 2003/11/30. How about this ? Any chance ?

  7. #7
    Join Date
    Jan 2002
    Location
    Berlin
    Posts
    72
    Sorry guys,

    I am really dump !!!

    All i needed is the following:

    select getdate()-(datepart(dd,getdate() )


    thx for your effort

  8. #8
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    Originally posted by dajm
    select getdate()-(datepart(dd,getdate() )
    Brilliant !!!
    Get yourself a copy of the The Holy Book

    order has no physical Brett in The meaning of a Kaiser . -database data

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •