I think you should put some trace-statements within your which return your do while variables, especially something like vweekstart - vweekend to see could it be calculated. In general it's recommended to use for each calculation or comparison numeric values, maybe something like this: