How do you extract the month?

How do you extract the month?

Question: You have been given a date in a string: “10/15/2020”. What is the best way to extract the month?

  •   Split function
  •   intr function
  •   Left
  •   Right

Answer

Option A is correct.

Using the split function is the best and easiest way. If you split using “/” as the split character, you end up with an array with each section before and after the character as the entry. Instr will at best tell you there is a certain month in there. Using Left may work but you have to capture for the fact that the month may be one or two characters. Right is worse as it will give you the same issues as Left, except you have to also account for the day being single or double characters.

Please subscribe to Cameron's YouTube channel