You can use the 'DAY' format of the date, but i m not sure how you can select a range using it.
SELECT *
FROM your_table_name
WHERE TO_CHAR(your_date_column,'
OR TO_CHAR(your_date_column,'
Main Topics
Browse All TopicsHI There,
I'm wondering how I can get a range of dates and times based on day names? For example how can I select between midday wednesday and midnight sunday?
Sean
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
@jinesh_kamdar: TO_CHAR is for Oracle, and does not exist in MS SQL server
>Yes that's correct. past midday on wednesday and then before midnight on sunday.
but WHICH wednesday / sunday?
ie, in the following cases, "now" is, October 03, 2007:
* wednesday , 08:00
* wednesday , 12:00
* wednesday , 14:00
what date/time do you want to "start", in those 3 cases?
please explain with "plain enlgish" rules.
please check the following "loop" to check if the results are what you expect as "logic":
declare @d datetime
declare @w datetime
declare @s datetime
set @d = getdate() - 14
while @d < getdate()
begin
set @w = dateadd(day, case when datepart(weekday, @d) < 4 then - datepart(weekday, @d) - 3
when datepart(weekday, @d) > 4 then 4 - datepart(weekday, @d)
when datepart(hour, @d) < 12 then - datepart(weekday, @d) - 3
else 4 - datepart(weekday, @d) end , @d )
set @w = dateadd(hour,12,convert(da
set @s = dateadd(day, 4, @w)
select @d date_value, datename(weekday, @d) date_name, @w wednesday_start, @s sunday_end
set @d = dateadd(day, 1, @d)
end
if it is, then, your query goes like this:
declare @d datetime
declare @w datetime
declare @s datetime
set @d = getdate()
set @w = dateadd(day, case when datepart(weekday, @d) < 4 then - datepart(weekday, @d) - 3
when datepart(weekday, @d) > 4 then 4 - datepart(weekday, @d)
when datepart(hour, @d) < 12 then - datepart(weekday, @d) - 3
else 4 - datepart(weekday, @d) end , @d )
set @w = dateadd(hour,12,convert(da
set @s = dateadd(day, 4, @w)
select * from yourtable
where yourdatefield >= @w
and yourdatefield < @s
Hi angelIII,
I not getting the results that I expected. The wednesday_start value is a friday and the sunday_end is a tuesday. Can you have a look at it please?
declare @w datetime
declare @s datetime
set @d = getdate() - 14
while @d < getdate()
begin
set @w = dateadd(day, case when datepart(weekday, @d) < 4 then - datepart(weekday, @d) - 3
when datepart(weekday, @d) > 4 then 4 - datepart(weekday, @d)
when datepart(hour, @d) < 12 then - datepart(weekday, @d) - 3
else 4 - datepart(weekday, @d) end , @d )
set @w = dateadd(hour,12,convert(da
set @s = dateadd(day, 4, @w)
select @d date_value, datename(weekday, @d) date_name, @w wednesday_start, @s sunday_end
set @d = dateadd(day, 1, @d)
end
| date_value | dayname | wednesday_start | sunday_end
2007-09-22 10:27:41.507 Saturday 2007-09-19 12:00:00.000 2007-09-23 12:00:00.000
Business Accounts
Answer for Membership
by: angelIIIPosted on 2007-10-03 at 03:20:36ID: 20005170
you will need to create a user defined function that translates the text into a concreate date.
am I right that with midday wednesday, you mean past wednesday 12:00PM ?