Solved

Calendar day render, sql query that get dates which have month the same as month rendered.

Posted on 2012-04-09
10
436 Views
Last Modified: 2012-04-10
Hi Guys,

Using C# and asp.net I want an sql query to get all eventDates that are in the month being rendered, how can I do this using sql or C#.

protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)

string selectStatement = "SELECT * FROM Events WHERE eventDate >= GETDATE()";
0
Comment
Question by:dizzycat
  • 5
  • 5
10 Comments
 
LVL 23

Expert Comment

by:wdosanjos
ID: 37824331
Try:
string selectStatement = "SELECT * FROM Events WHERE eventDate >= dateadd(day, -day(getdate()) + 1, cast(getdate() as date))"

Open in new window

0
 

Author Comment

by:dizzycat
ID: 37824452
The query still gets every eventDate from the database.
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 37824482
Please provide some sample data indicating what is in the database and what you want to be selected.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:dizzycat
ID: 37824572
lets say I have got 5 eventDates in the database:

April 02
April 14
April 23
April 27
May  11

I want all eventDates that are greater than or = to todays date and eventdates that are in the same month as the current month displayed by the calendar.
IE if the calendar current month was April, than I would want the query to retrieve the below eventDates:

April 14
April 23
April 27
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 37824677
SELECT * FROM Events 
 WHERE eventDate >= cast(dateadd(day, -day(getdate()) + 1, getdate()) as date)
   AND eventDate < dateadd(month, 1, cast(dateadd(day, -day(getdate()) + 1, getdate()) as date))

Open in new window

0
 

Author Comment

by:dizzycat
ID: 37824876
The query is still not quite right, it is returning the eventDates:

April 02
April 14
April 23
April 27

When the calendars displayed month is April.
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 37824913
That seems correct to me.  It displays April dates when the month is April.  Please clarify.
0
 

Author Comment

by:dizzycat
ID: 37824939
Sorry if I didn't make it clear but i want the dates returned to be greater than or equal todays date as well as being in the same month as being displayed by the calendar.
0
 
LVL 23

Accepted Solution

by:
wdosanjos earned 500 total points
ID: 37824950
OK. There you go:
SELECT * FROM Events 
 WHERE eventDate >= cast(getdate() as date)
   AND eventDate < dateadd(month, 1, cast(dateadd(day, -day(getdate()) + 1, getdate()) as date))

Open in new window

0
 

Author Comment

by:dizzycat
ID: 37825034
That's great thanks for your help.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question