Calendar Select does not select a date if datetime value contains a time other than midnight

If you set a Calendar control SelectedDate with a DateTime where the there is a date part, and a time of 00:00:00, the calendar correctly selects that date

If the time part is not midnight, the Calendar does not select the date.

I used the DateTime.Date value to set the date from a DateTime value with non-midnight dates

Is this a bug? or by quirky design

If it was easy, everybody would be doing it.
9/14/2006 7:22:28 PM 93655 articles. 6 followers. Follow

6 Replies

Similar Articles

[PageSpeed] 10

I could be wrong but more like quicky design because past midnight is in the 24hour clock which is in TimeSpan.

Kind regards,
Gift Peddie
9/14/2006 8:20:05 PM

The selected date property accepts the type of DateTime.  It should therefore be able to extract the day/month/year out of this class and ignore the time part - which is how you and I would write the code!  As I elucidated, the DateTime class already has a property that provides this, as well as other properties for day/month/year.

I am not sure why you think a time span is important.  This is a different class supporting a different concept, and cannot be used to get a static date time

If it was easy, everybody would be doing it.
9/18/2006 8:27:30 AM

Yes I know they don't appear related but past midnight is multiple dates and I told you I could be wrong.  Run a search on your problem you only find references to Oracle 10g docs why simple past midnight is time interval. I have seen you do time for users so you will find a solution but it is not a bug.

Kind regards,
Gift Peddie
9/18/2006 3:28:42 PM

Regardless of the calendar selection mode used, using a date time to select a single date with a time not equal to midnight does not perform a selection.

The time span is only relevant as when reading a range of dates already selected in the calendar, where the selected dates collection can be used to provide the first/last fixed position in time to create an abstract length of time (the timespan object)

A simple test

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<script runat="server">

protected void lnkDate_Click(object sender, EventArgs e)


DateTime dt = new DateTime(2006, 9, 21);

Calendar1.SelectedDate = dt;

Calendar1.VisibleDate = dt;


protected void lnkDateTime_Click(object sender, EventArgs e)


DateTime dt = new DateTime(2006, 9, 21, 12, 0, 0);

Calendar1.SelectedDate = dt;

Calendar1.VisibleDate = dt;



<html xmlns="">

<head runat="server">

<title>Untitled Page</title>



<form id="form1" runat="server">

<asp:LinkButton ID="lnkDate" runat="server" OnClick="lnkDate_Click">Set 21-Sep-2006</asp:LinkButton>

<asp:LinkButton ID="lnkDateTime" runat="server" OnClick="lnkDateTime_Click">Set 21-Sep-2006 12:00:00</asp:LinkButton>


<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>





If it was easy, everybody would be doing it.
9/18/2006 10:58:14 PM

Hi sbyard,

This is a very interesting find. I have reproduced your sample and can confirm if the "time" portion of the date is not midnight (12:00 AM) the SelectedDate will not be set.

I've been working with the Calendar control weekly for 5+ years and never ran into this problem before. It's really strange.

I'm going to do some digging and see if I can find where things are going wrong within the control. They (Microsoft) are probably doing a straight comparison of the SelectedDate value to the date of the Cell being rendered. If they don't match, the SelectedDate is not rendered. For example:

(DateTime.Today == DateTime.Now) // returns false

What I think should be happening is something like the following...

(DateTime.Today.ToShortDateString() == DateTime.Now.ToShortDateString()) // returns true

By removing the "Time" portion of the DateTime value, you can compare if the "days" are the same.

Hope that makes sense.

I'll let you know what I find out.

Geoffrey McGill - Product Manager
Basic Date Picker - A Quicker Picker(TM) - ASP.NET Calendar, Date and Time Web Controls
9/18/2006 11:25:49 PM

Given that the DateTime class already has a property for the DAY part only, you would think that this would be used for teh comparison.  But, as you allude, if there is a comparison between a DateTime and some other non-DateTime value, then a conversion is requried one way or the other.  You can always use the standard calendar as a base class and coreect the issue by overriding the selected date property - as long as it's overridable, or even create a "new" property at the inherited level, and calling the base class.

 Ho Hum

 PS.  If you see Derrick Zaychuck in Edmonton (has has a trucking company), say Hi. for me!

If it was easy, everybody would be doing it.
9/19/2006 9:33:28 AM

Similar Artilces:

Form: Focus on selected values in dropdownlists, Refresh after selection and hidding formfields based on selection.
Hello again,I have a form with several dropdown lists. Depending on the selected value in the dropdown lists other fields become available in that same form. It is working in classic ASP in combination of JavaScript. I want to migrate it to ASP.NET. I have posted a part of the form at the end of this post.My questions:1. I use <option <%If iFood="0" then%>selected<%End If%> value="0">No value selected</OPTION> to select the selected item when the form is reloaded after the selecting. I know that this also works in ASP.NET, but isn't there a typical ASP....

Raise Event when a selected date is selected again in Calendar
Hi all,When I view source of the rendered page that contains a calendar control, I see it's a table, with a child table where each date is a table cell calling the all powerful __dopostback function with the calendar id as the event target and a unique numeric string as the event argument.Since the selected date is also containing the dopostback function, could that be exploited to call a routine during page load due to postback.I have come upto this and got stuck after that.'aspx.vb code snippet:If TypeOf sender Is Control Then     dim ctl as control  &...

Selecting already selected date in Calendar control
Greetings,  I have a calendar control inside an UpdatePanel. As indicated in the documentation (and verified by testing), the SelectionChanged event is triggered only if the selected date is changed. That is, it does not trigger if the user clicks on the already selected date.  However, clicking on the already selected date does cause an async postback of the UpdatePanel that contains the calendar.  So, my question -- how can I determine that the cause of the postback was the user clicking a second time on the calendar control? There does not appear to be a ...

Parse DateTime into Date or select DateTime as Date from Access
I am getting DateTime values out of an Access Database and I want to only use the Date part of this field. I have tried to cast the returned value to a DateTime value and then format the DateTime to only show the Date part in the toString() fcn. <asp:Label runat="server" Text='<%# getDate(DataBinder.Eval(Container, "DataItem.ACTIVE_FROM"))%>'> But I can't cast the object to a DateTime object. I have also tried using DateTime.Parse() but this gives an error saying that the format is not correct.         {       ...

How to use Select case statement to select web form controls
Hi; I don't know why I can't conceptionalize  this but I want to take these if statements and put them in a select case. I am testing for multiple selection from several DDLs on my web form.   If DropDownList1.SelectedIndex > -1 And DropDownList2.SelectedIndex > 0 Then If Me.CheckBox1.Checked Then ObjectDataSource1.FilterExpression = "assignee = {0} AND assignor = {1}" Else ObjectDataSource5.FilterExpression = "assignee = {0} AND assignor = {1}" End If End If If DropDownList1.SelectedIndex > -1 And DropDownList3.SelectedIndex >...

Hi! I remember seeing an example where you can do a select from a nested select, but I cannot seem to make it work. So it would be something like this: select max( name ) from ( select name from customer union select name from vendor ) Was I dreaming I saw that? Thanks! D In article <4500243f@forums-2-dub>, says... > Hi! > > I remember seeing an example where you can do a select from a nested > select, but I cannot seem to make it work. No, you weren't. Try (UNTESTED!) adding a...

How can I have the selected month came up by default in the Calendar control if a date is selected?
I am using .net 1.1.  I set a default date to a Calendar control, for example Calendar1.SelectedDate = "10/1/2007" when the page was loaded.  When the Calendar came up, the current month was shown.  I clicked the previous arrow to October and 10/1/2007 was selected. How can I have the October (or the selected month) came up by default?  Thanks. DanYeung I figured it out.  Set Calendar1.VisibleDate = "10/1/2007". DanYeung...

HTML select , selected value changes when clicking refresh multiple times Can anyone think of a workaround? The bug is causing us major issues, leading our users to think data is changing for no apparent reason. This same thing happens if you use the back button as well. Thanks in advance! Jerry DuVal Pace Systems Group, Inc. 800.624.5999 ...

Dropdownlist selected value passes first value in list no matter what value is selected. why ?
 HI . I have a dropdownlist. Databinds ok but when I must pass a value as a Selected value it always passes the first value in the list even if I select another value. I tried to set the ddl to enableviewstate false but it doesn't change anything. Any ideas ? Code below, thanksLoading the ddl:       productCategories = CatalogAdmin.Admin_Product_Categories_NotIn(productId);        for (int i = 0; i < productCategories.Rows.Count; i++)        {       &...

Forms , Select and option selected.
Name: Jirrick Email: jurahudecatgmaildotcom Product: Firefox Release Candidate Summary: Forms , Select and option selected. Comments: I've found problem with SELECTED option in <select> forms. I wanted to use pre-selected option in my form , but when I used the Firefox 3 RC1 to render it there wasn't any preselected item. I tried to rewrite code ( use selected="selected" ) , but still no effect. I was confused and tried to use others viewers ( IE 8 , OP 9 , Konqueror ) and the pre-selected item worked well in these browsers. The bug has to be in FF 3 ...

Hi all, i am using C# , vs2005. ajax 1.0 i am populating data programitically . when i select first value, dropdown control select the same. when i select second value ,dropdownlist select second value too But i does not continue  from third value onward . when i select third value, dropdownlist control select second value then after behavior reman the same no matter what i select dropdownlist control select second value ONLY.<asp:DropDownList id="Ddlzse" runat="server" Width="165px" Font-Bold="False" Fo...

Accessing the selected value from a Select
Need to access the selected value from a Select in client script.  I can get the selectedIndex but where do I find the selected value? Will this give it to me? form1.Select1.Options(form1.Select1.SelectedIndex)   form1.Select1.options[form1.Select1.selectedIndex] Try form1.Select1.options[form1.Select1.selectedIndex].value> penny for a thought...

Can you please help..Calendar Didn't select the Date I want it selected..
Here is my code, in Page_load , find out what the week the day is and then set the Calendar's Start Time as last Monday and End Time as last Sunday.. these code didn't works on page_load.. but I don't know what's going wrong.. can you please help me to correct my code?1 private void Page_Load(object sender, System.EventArgs e) 2 { 3 // 4 if(!Page.IsPostBack) 5 { 6 string todayWeek = DateTime.Now.DayOfWeek.ToString(); 7 switch(todayWeek) 8 { 9 case "Monday": 10 catchDate(-7,-1); 11 b...

Selecting non continuous dates in the .net calendar control
Is there a way to select non continuous dates using the calendar control. I know you can select a single date, entire week, or entire month, but I want to give my user the ability to select non continuous dates like July 1, July 10, July 25, July 26, and July 27 and then submit that to the server. Any ideas?...

Web resources about - Calendar Select does not select a date if datetime value contains a time other than midnight -

The beard calendar
How am I not in this? ∞ Read this on The Loop

Thai solar calendar - Wikipedia, the free encyclopedia
The Thai solar calendar , Suriyakhati ( Thai : สุริยคติ ) was adopted by King Chulalongkorn (Rama V) in AD 1888 as the Siamese version of the ...

Introducing the new Calendar Resource API
... Work and Wesley Chun , Developer Advocate, Google Apps Over the years, we’ve been updating our APIs with new versions across Drive and Calendar, ...

Calendar: Week of December 14 - Videos - CBS News
From the unveiling of Merriam-Webster's Top 10 Words of the Year, to the unveiling of "Star Wars: The Force Awakens" - "Sunday Morning" takes ...

Tomsula: 49ers building for future, 'on a one week calendar'
Enter to win prizes during the entire month of January! You can win tickets to a Warriors game, CSN studio tours, a chance to attend the Coaching ...

Entertainment calendar
New Year’s Eve parties, club events, live music and more this week in Metro Detroit Entertainment calendar New Year’s Eve parties, club events, ...

A-Zdvent calendar: University of Limerick Living Bridge by Wilkinson Eyre
As we enter the final week of our bridge countdown, we're spotlighting the University of Limerick Living Bridge in Ireland by Wilkinson Eyre ...

Pair Aims to Scrap the Gregorian Calendar by 2017
Two Johns Hopkins professors hope we’ll all be using a new calendar soon.

Planning Your 2016 Content Marketing Calendar
Planning Your 2016 Content Marketing Calendar written by Guest Post read more at Duct Tape Marketing There are only a few weeks left in 2015, ...

Ashley Graham Shows Off Sexy Pink Lingerie for 'Love' Magazine's Advent Calendar
The model and body activist shakes her stuff for the publication's latest holiday installment.

Resources last updated: 1/4/2016 11:29:06 AM