Solved

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

Posted on 2012-04-09
10
429 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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now