[Last Call] Learn how to a build a cloud-first strategyRegister Now


asp calendar datetime format

Posted on 2009-12-22
Medium Priority
Last Modified: 2012-08-13
i have a calendar that displays the information for a date that has been selected on the calendar in a gridview.when a date starts with a zero ie 2009/12/07 nothing is displayed but works for my other dates like 2009/12/22.what am i missing?
here is my code
<asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged"
                                    BorderWidth="1px" NextPrevFormat="FullMonth" BackColor="White" Width="350px"
                                    ForeColor="Black" Height="190px" Font-Size="9pt" Font-Names="Verdana" BorderColor="White">
                                    <TodayDayStyle BackColor="#CCCCCC"></TodayDayStyle>
                                    <NextPrevStyle Font-Size="8pt" Font-Bold="True" ForeColor="#333333" VerticalAlign="Bottom">
                                    <DayHeaderStyle Font-Size="8pt" Font-Bold="True"></DayHeaderStyle>
                                    <SelectedDayStyle ForeColor="White" BackColor="#333399"></SelectedDayStyle>
                                    <TitleStyle Font-Size="12pt" Font-Bold="True" BorderWidth="4px" ForeColor="#333399"
                                        BorderColor="Black" BackColor="White"></TitleStyle>
                                    <OtherMonthDayStyle ForeColor="#999999"></OtherMonthDayStyle>
                                <span class="mainheading">Event Location and Dates</span><br />
                                <br />
                                <asp:GridView ID="CalendarList" runat="server" Width="450px" AutoGenerateColumns="False"
                                    CssClass="gridtable" CellPadding="5" BorderColor="#ff3300" BorderWidth="1px"
                                    <AlternatingRowStyle BackColor="#F8F8F8" />
                                        <asp:TemplateField HeaderText="EventLocation" HeaderStyle-CssClass="gridheading">
                                                <asp:Label ID="EventLocLabel" runat="server" Text='<%# Eval("EventLocation") %>'>
                                        <asp:TemplateField HeaderText="EventDate" HeaderStyle-CssClass="gridheading">
                                                <asp:Label ID="EventDateLabel" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "EventDate") %>

protected void Page_Load(object sender, EventArgs e)
    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
        Calendar Calendar1 = (Calendar)Form.FindControl("Calendar1");
        string connCalendarString = ConfigurationManager.AppSettings["THConnectionString"];
        MySqlConnection cnxCalendar = new MySqlConnection(connCalendarString);
        MySqlDataAdapter adapterCalendar = new MySqlDataAdapter();
        string cmdCalendarText = ("SELECT EventLocation, EventDate FROM eventstable WHERE EventDate = ?EventDate");
        MySqlCommand cmdCalendar = new MySqlCommand(cmdCalendarText, cnxCalendar);
        cmdCalendar.Parameters.Add(new MySqlParameter("EventDate", Calendar1.SelectedDate.ToString("yyyy/MM/dd")));
        DataSet dsCalendar = new DataSet();
        adapterCalendar.SelectCommand = cmdCalendar;
        GridView CalendarList = (GridView)Form.FindControl("CalendarList");
        CalendarList.DataSource = dsCalendar;

Question by:chrispaton
  • 5
  • 2
LVL 18

Expert Comment

by:Elvio Lujan
ID: 26104557
can you set a break point in the line
cmdCalendar.Parameters.Add(new MySqlParameter("EventDate", Calendar1.SelectedDate.ToString("yyyy/MM/dd")));
and tell us what value you get with "Calendar1.SelectedDate" ??

Author Comment

ID: 26104600
the value is {07/12/2009 00:00:00}
LVL 18

Expert Comment

by:Elvio Lujan
ID: 26104644
and why do you use the format "yyyy/MM/dd" intead "MM/dd/yyyy"???
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

ID: 26104661
That way seems to be the only way i have found so far that pulls any dates from my table

Author Comment

ID: 26104807
With the date as "MM/dd/yyyy" i get nothing returned.in my table the dates are stored as 2009-12-30

Expert Comment

ID: 26104899
Hi chrispaton,

Kindly navigate to the below url and let me know you got the exact solution for the problem...

Abel Allen

Author Comment

ID: 26104973
no it's still not pulling dates that start with a zero ie 2009/12/07

Accepted Solution

chrispaton earned 0 total points
ID: 26105301
ok fixed it there was a problem with my database

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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. …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month18 days, 6 hours left to enroll

830 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