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.
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.
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.
I hope these will help you create concise code.
Leave a Reply