in your script or Database write a case statement saying that if week=wednesday assign the number as 1 and thursday as 2.. friday as 3 , saturday as 4 , sunday as 5 , monday as 6 , Tuesday as 7 into a column say Week_flag. Us this column for your calculations purpose. Hope this helps.