troubleshooting Question

User-Defined Function with Date

Avatar of Yongshu Li
Yongshu LiFlag for United States of America asked on
Microsoft SQL Server
27 Comments6 Solutions1306 ViewsLast Modified:
I need to have the following funtion in Access converted into an MS SQL Server 2000 User-Defined Function. Would anyone be able to help? Or Would anyone know a book that offers the most often used user-defined functions such as first/last day of month, quarter, year, with an OPTIONAL parameter to pass, in MS SQL Server 2000?

Appreciated!!!

'   Get the last day of current month.
Public Function fncGetEndOfMonth(Optional dtmDate As Date = 0) As Date
   
    ' Did the caller pass in a date? If not, use the current date.
    If (dtmDate = 0) Then
        dtmDate = Date
    End If
       
    fncGetEndOfMonth = DateSerial(Year(dtmDate), Month(Date) + 1, 0)

End Function
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 6 Answers and 27 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 6 Answers and 27 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros