An enhanced VB DatePart function

An enhanced VB DatePart function

Here is an enhanced version of VB DatePart function: the first parameter is now an enumerated type, so easier to use. DatePartEx is 4-5 times faster than DatePart and supports also two new intervals: MonthName and WeekdayName.

Enum DateTimePart    dtYear    dtQuarter    dtMonth    dtMonthName    dtShortMonthName    dtDay    dtDayOfTheYear    dtWeekday    dtWeekdayName    dtShortWeekdayName    dtWeekOfTheYear    dtHour    dtMinute    dtSecondEnd Enum' Enhanced VB DatePart functionFunction DatePartEx(ByVal Interval As DateTimePart, newDate As Date, _    Optional FirstDayOfWeek As VbDayOfWeek = vbSunday, Optional FirstWeekOfYear _    As VbFirstWeekOfYear = vbFirstJan1) As Variant    ' Select the right and faster date/time function    Select Case Interval        Case dtYear            DatePartEx = Year(newDate)        Case dtQuarter            DatePartEx = DatePart("q", newDate, FirstDayOfWeek, FirstWeekOfYear)        Case dtMonth            DatePartEx = Month(newDate)        Case dtMonthName            DatePartEx = MonthName(Month(newDate), False)        Case dtShortMonthName            DatePartEx = MonthName(Month(newDate), True)        Case dtDay            DatePartEx = Day(newDate)        Case dtDayOfTheYear            DatePartEx = DatePart("y", newDate, FirstDayOfWeek, FirstWeekOfYear)        Case dtWeekday            DatePartEx = Weekday(newDate, FirstDayOfWeek)        Case dtWeekdayName            DatePartEx = Format(newDate, "dddd")        Case dtShortWeekdayName            DatePartEx = Format(newDate, "ddd")        Case dtWeekOfTheYear            DatePartEx = DatePart("ww", newDate, FirstDayOfWeek, _                FirstWeekOfYear)        Case dtHour            DatePartEx = Hour(newDate)        Case dtMinute            DatePartEx = Minute(newDate)        Case dtSecond            DatePartEx = Second(newDate)    End SelectEnd Function

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several