ASP Month Number from Month Name

ASP Best Practices

ASP comes with a function to turn a number into a month name but what if you have the month name and want the number? Here's how.

Date : 2006-03-09
ASPs date functions have shorted us again. Here is a quick and simple method of getting the Month Number from a full month name or even an abbreviated month name.

Function MonthNumber(m_name)
  tmn = 0
  m_name = trim(m_name)
  for x=1 to 12
    if (strcomp(m_name,MonthName(x,false),vbTextCompare) = 0) OR (strcomp(m_name,MonthName(x,true),vbTextCompare) = 0) then
      tmn = x
      exit for
    end if
  MonthNumber = tmn
End Function

This function is the opposite of the MonthName(MonthNum) function. Let me know if you can think of any optimizations to this function.

Comments :

No comments yet
  • Search For Articles