In other words, the code you posted will always return null. If your application is working, you did not post the code your application is using. The end time cannot simultaneously be <= the start of the week and >= the end of the week. Since that was probably a typo, go with aby's answer. You'll probably need a date() function around weekstart() too, though.