Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2012-04-09
10
Medium Priority
?
448 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

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

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

604 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