• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 450
  • Last Modified:

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()";
0
dizzycat
Asked:
dizzycat
  • 5
  • 5
1 Solution
 
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
 
wdosanjosCommented:
Please provide some sample data indicating what is in the database and what you want to be selected.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 
wdosanjosCommented:
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
 
dizzycatAuthor Commented:
That's great thanks for your help.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now