• RV
    • Missy – My Home
    • JBAM – Newmar Dutch Star
    • Shaneeda
    • Buying a Used RV
    • Gas vs Diesel RVs
    • Ideal Motorhome
    • Choosing the Ideal RV
  • Cycling
  • Jeep
  • About
  • Flying
    • Vans RV-4
    • Daisy – RV-3B
  • Resources
  • Subscribe

JdFinley.com

Fulltime RV Living Adventures

  • Is Solar For You?
  • Gas vs Diesel RVs
  • Buying a Used RV
  • Choosing the Ideal RV
  • Ideal Motorhome

T-SQL End Dates with DateAdd

October 8, 2011

Microsoft SQL Server 2000 2005 2008 T-SQL Tips How-To Development Programming

We covered some “begin” T-SQL DateTime routines in this previous post.  This time around, we’ll do some end date routines using DateAdd. The concept is the same; when developing stored procedures, functions, and scripts for a Microsoft SQL Server database, you often need these values, particularly when reporting and/or searching date ranges.

Function that returns the last day of the month using the input date as the starting point. When 5/15/2004 is input, the output will be 5/31/2004 23:59:59.997.

DATEADD(ms,-3, DATEADD(mm, DATEDIFF(m, 0, @InputDate)+1, 0))

Function that returns the last day of the year using the input date as the starting point. When  5/15/2004 is input, the output will be 1/1/2004 23:59:59.997.

DATEADD(ms, -3, DATEADD(yy, DATEDIFF(yy,0, @InputDate)+1, 0))

Function that returns the last second of the day using the input date as the starting point. When  5/15/2004 is input, the output will be 5/15/2004 23:59:59.997.

DATEADD(ms, -3, DATEADD(dd, DATEDIFF(d, 0, @InputDate)+1, 0))

I hope these will help you create concise code.

(Visited 247 times, 1 visits today)

Related posts:

Default ThumbnailT-SQL Begin Dates Default ThumbnailWhat is SQL? Default ThumbnailCompare Date Values Default ThumbnailSQL Common Table Expressions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Everything will be all right in the end, if it’s not all right, it’s not the end.

— Unknown

Popular Posts

  • Powermatic Model 90 Wood Lathe & VFD
  • Wood Turning on a Lathe
  • Chainsaw Review: Sportsman 20 in. 52cc
  • Cielo Grande Barbed Wire Fence Repair

Email Notification


 

Posts by Subject

3DPrinting Aircraft Airstrip Bible Bus bus boys Camping Cat Computers Cycling Development Electrical electronics Entertainment Environment Factory Five family FAQ Finances flying Food God Health Holiday Home Humor kayak Life Maintenance Nature Photography Review RV-3 RV-4 sailboat sailing self improvement Sewing solar Travel Video weather wood woodworking X-Country

Posts by Month

© Copyright © 2025 JDFinley.com · All Rights Reserved · Privacy Policy

Unauthorized use and/or duplication of this material without express and written permission from this site’s author and/or owner is strictly prohibited. Excerpts and links may be used, provided that full and clear credit is given to JD Finley and JdFinley.com with appropriate and specific direction to the original content.