SQL Server Performance

Query to get the last date of the previous month.

Discussion in 'SQL Server 2005 General Developer Questions' started by Varsha, May 22, 2008.

  1. FrankKalis Moderator

    [quote user="ABSINTHIST"]
    Great job Frank, but how does this one work?
    [/quote]
    I think I've described this technique here http://www.sql-server-performance.com/articles/dev/datetime_datatype_p1.aspx on one page.
    The only differences between the example in my article and here in my script is the -1 as start date. 0 is the 1st day of January 1900. Adding months' to this date always results in another 1st day of another month. Likewise -1 is the last day of the month before January 1900, that is December 1899. Any number of months' added to this date results in the last day of the previous month. Hope I haven't confused you, I for one sucessfully confused myself now, I think. [:)]
  2. Varsha New Member

    Ok thats what i wanted. Thanks a lot!! Although i am still not very clear with the logic you have applied will try to get in depth of it.
  3. FrankKalis Moderator

    [quote user="Varsha"]
    Ok thats what i wanted. Thanks a lot!! Although i am still not very clear with the logic you have applied will try to get in depth of it.
    [/quote]
    If you feel more comfortable with Kenneth' solution, go for that. There might be an ever so small performance hit, but it will definitely be easier for you to maintain a solution you fully understand when you come back to this piece of code in the future.
  4. Varsha New Member

    No the solution that you have given is perfect. I am going with your approach.

Share This Page