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

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()";
dizzycatAsked:
Who is Participating?
 
wdosanjosConnect With a Mentor Commented:
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
 
wdosanjosCommented:
Try:
string selectStatement = "SELECT * FROM Events WHERE eventDate >= dateadd(day, -day(getdate()) + 1, cast(getdate() as date))"

Open in new window

0
 
dizzycatAuthor Commented:
The query still gets every eventDate from the database.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
wdosanjosCommented:
Please provide some sample data indicating what is in the database and what you want to be selected.
0
 
dizzycatAuthor Commented:
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
 
wdosanjosCommented:
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
 
dizzycatAuthor Commented:
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
 
wdosanjosCommented:
That seems correct to me.  It displays April dates when the month is April.  Please clarify.
0
 
dizzycatAuthor Commented:
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
 
dizzycatAuthor Commented:
That's great thanks for your help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.