Ah... almost forgot. Neither Scott's nor mine checks to make sure the values of YYYY and MM are actually part of a valid date. Ostensibly, that's already been checked but if the data is from a 3rd party source, then use Jason's. Thom's code also does the date check but Jason's is faster.
--Jeff Moden
Change is inevitable... Change for the better is not.