473,382 Members | 1,313 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Calendar calculation

Hi all,

Does the calendar control provide any easy way to detect the last day
of the currently displayed month? I'm using the VisibleMonthChanged
event, and can find the first day of the month using e.NewDate.
I need to find the last date day of the month to pull month specific
data from a database (Rather than pulling everything).
Any help or tips on how to calculate this would be appreciated.

Thanks.

Jun 8 '06 #1
8 1971

^MisterJingo^ wrote:
Hi all,

Does the calendar control provide any easy way to detect the last day
of the currently displayed month? I'm using the VisibleMonthChanged
event, and can find the first day of the month using e.NewDate.
I need to find the last date day of the month to pull month specific
data from a database (Rather than pulling everything).
Any help or tips on how to calculate this would be appreciated.

Thanks.


Why not make the month part of you SQL eg:
select * from TABLE where datepart(Mm,DATEFIELD) = @MONTH_VALUE and
datepart(Yy,DATEFIELD) = @YEAR_VALUE

Jun 8 '06 #2
How about using e.NewDate.DaysInMonth? You could then replace the days
element of your date with this integer, e.g.

int intDay = e.NewDate.DaysInMonth;

string strDate = e.NewDate.ToString("MM/dd/yyyy HH:mm:ss");

strDate = strDate.Substring(0,(strDate.IndexOf("/",0)) -1) + intDay +
strDate.SubString(strDate.IndexOf("/",0) + 4) ;

DateTime dteDate = Convert.ToDateTime(strDate);

I've not tried this, so it might not work and there is probably a
simpler method.

Jared
^MisterJingo^ wrote:
Hi all,

Does the calendar control provide any easy way to detect the last day
of the currently displayed month? I'm using the VisibleMonthChanged
event, and can find the first day of the month using e.NewDate.
I need to find the last date day of the month to pull month specific
data from a database (Rather than pulling everything).
Any help or tips on how to calculate this would be appreciated.

Thanks.


Jun 8 '06 #3

Richard Brown wrote:
^MisterJingo^ wrote:
Hi all,

Does the calendar control provide any easy way to detect the last day
of the currently displayed month? I'm using the VisibleMonthChanged
event, and can find the first day of the month using e.NewDate.
I need to find the last date day of the month to pull month specific
data from a database (Rather than pulling everything).
Any help or tips on how to calculate this would be appreciated.

Thanks.


Why not make the month part of you SQL eg:
select * from TABLE where datepart(Mm,DATEFIELD) = @MONTH_VALUE and
datepart(Yy,DATEFIELD) = @YEAR_VALUE


Hi Richard,

Thanks for the above. The problem is that i'm currently using MySQL as
the DB and it doesn't have a datepart function. I'm looking for
something similar in its documentation.

Jun 8 '06 #4

Jared wrote:
How about using e.NewDate.DaysInMonth? You could then replace the days
element of your date with this integer, e.g.

int intDay = e.NewDate.DaysInMonth;

string strDate = e.NewDate.ToString("MM/dd/yyyy HH:mm:ss");

strDate = strDate.Substring(0,(strDate.IndexOf("/",0)) -1) + intDay +
strDate.SubString(strDate.IndexOf("/",0) + 4) ;

DateTime dteDate = Convert.ToDateTime(strDate);

I've not tried this, so it might not work and there is probably a
simpler method.

Jared


Hi Jared,

Thanks for this. It turns out e.NewDate hasn't got the DaysInMonth
method, so I did the following:

int day = DateTime.DaysInMonth(e.NewDate.Year, e.NewDate.Month);

start = e.NewDate;
end = new DateTime(e.NewDate.Year, e.NewDate.Month, day);

start and end are datetimes used the in the SQL statement

Jun 8 '06 #5

^MisterJingo^ wrote:
Richard Brown wrote:
^MisterJingo^ wrote:
Hi all,

Does the calendar control provide any easy way to detect the last day
of the currently displayed month? I'm using the VisibleMonthChanged
event, and can find the first day of the month using e.NewDate.
I need to find the last date day of the month to pull month specific
data from a database (Rather than pulling everything).
Any help or tips on how to calculate this would be appreciated.

Thanks.


Why not make the month part of you SQL eg:
select * from TABLE where datepart(Mm,DATEFIELD) = @MONTH_VALUE and
datepart(Yy,DATEFIELD) = @YEAR_VALUE


Hi Richard,

Thanks for the above. The problem is that i'm currently using MySQL as
the DB and it doesn't have a datepart function. I'm looking for
something similar in its documentation.


Looks like you have this sorted from your later posts:

But if not note that mySQL appears to support MONTH(date) and
YEAR(date) functions, I've not tested this as I don't have a mySQL db
but my guess is you could achieve the above using these.

Jun 9 '06 #6
Ok, I've get things working but I've noticed strange behaviour with
this control.

I use the following function to change a days colour if its date is in
the DB:
protected void Cal_DayRender(object sender, DayRenderEventArgs e)
{
if (!e.Day.IsOtherMonth)
{
foreach (DataRow dr in _ds.Tables[0].Rows)
{
if ((dr["startdate"].ToString() != DBNull.Value.ToString()))
{
Response.Write(dr["startdate"].ToString());
DateTime dtEvent = (DateTime)dr["startdate"];
if (dtEvent.Equals(e.Day.Date))
{
e.Cell.BackColor = System.Drawing.Color.PaleVioletRed;
}
}
}
}
}

The Response.Write is just used for testing. When this app is run, the
following is produced:

http://www.misterjingo.com/cal.gif

Does anyone have an idea why so many lines are being outputted? I set a
counter up to see how many times the foreach is run, and even if its
run 1 time, the same still happens. The above function is only called
once too.

Jun 9 '06 #7

^MisterJingo^ wrote:
Ok, I've get things working but I've noticed strange behaviour with
this control.

I use the following function to change a days colour if its date is in
the DB:
protected void Cal_DayRender(object sender, DayRenderEventArgs e)
{
if (!e.Day.IsOtherMonth)
{
foreach (DataRow dr in _ds.Tables[0].Rows)
{
if ((dr["startdate"].ToString() != DBNull.Value.ToString()))
{
Response.Write(dr["startdate"].ToString());
DateTime dtEvent = (DateTime)dr["startdate"];
if (dtEvent.Equals(e.Day.Date))
{
e.Cell.BackColor = System.Drawing.Color.PaleVioletRed;
}
}
}
}
}

The Response.Write is just used for testing. When this app is run, the
following is produced:

http://www.misterjingo.com/cal.gif

Does anyone have an idea why so many lines are being outputted? I set a
counter up to see how many times the foreach is run, and even if its
run 1 time, the same still happens. The above function is only called
once too.


The number of times the Response.Write text is repeated seems to
correlate to the number of days in the month. Is this normal behaviour?

Jun 9 '06 #8
I have one more question regarding this control. I know its possible to
change the tooltip text of a control, but is it possible to change the
'title' text of the default day number created by the control? As this
link dominates the cell, more often than not, people will see the title
text (day and month of the cell link under the mouse pointer) rather
than the tooltip text (around the link).
I've googled for a solution but cannot find anything yet.

Jun 9 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: john_woo | last post by:
Hi I'm stuck on creating a restrited selectable calerdar using javascript, say I want to popup a calendar (which is not difficult to many developer), but the difficulty to me is, how to make...
3
by: bp | last post by:
I'm using the System.Globalization.GregorianCalendar class to calculate week numbers. My weeks begin on Saturday and follow the "first four day" rule. GregorianCalendar cal = new...
38
by: George Sexton | last post by:
We're in the process of re-launching our web calendar product. We would like to get your opinions on a couple of things about our site and product. This is a relaunch of an existing product with...
0
by: larry | last post by:
I am in the process of rewriting one of my first PHP scripts, an event calendar, and wanted to share the code that is the core of the new calendar. My current/previous calendar processed data...
2
by: Kajsa Anka | last post by:
Before I re-invent something I would like to ask if there exists some code that can be used for create the HTML code for a calendar which I then can include on a web page. The module in the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.