Create date fields with common function
Fixed variable scope, removed unused variable assignment