Blue Theme Orange Theme Green Theme Red Theme
 
Skip Navigation Links
C# Corner Home
Forum Home
Latest 50
Unanswered
Win $500 Cash
All Time Leaders
Jump to CategoryExpand Jump to Category
Login 
    Welcome Guest!
 Search Forum For :  
X
 Login
Please login to submit a new post, reply and edit exiting posts, see user profiles, and access more features. If you are not a registered member, Register here.
User Id:
Password:  
Forgot Password | Forgot UserName
   Home » ASP.NET & Web Development » Change SelectedDate (DateTime) format
       
Author Reply
Deepayan Nandi
posted 1 posts
since Oct 20, 2009 
from

 Change SelectedDate (DateTime) format
  Posted on: 11/4/2009 4:03:13 PM       

I'm working on a page that has a regular calendar control, i bind "selectedDays" to a database and show these days with an offset background color.  This tells the user that a record exists on that day.  My next step is for the user to then click that date and in a RadDataGrid show all the records for that day.

At this time when i click a highlighted date that i know has a record, it will only show a matching record if it has a Date and Time stamp of 12:00:00 attached to it.  However the database has DateTime for when the record was created by the user.

Basically i want the SQL statement triggered by the SelectedDate property of the Calendar control to only send the format Month,Day,Year.  I'm not sure how i can control this.

At this time, my code is inline for the clicking of the date to populate the RadGrid.  The only codebehind is the code that displays the different background for SelectedDates with a record(s).
think the other part to mention is that there are two things to keep in mind.

1. The input from the Calendar Control which become the WHERE in my SQL Statement
1. Running my SQL statement
2. And outputing the date on the page (through RadGrid control)

I need to keep straight all of the inputs and outputs and make sure the formats are what i expect.

So, when i click a date on the calendar control.  Which is @ArticleDateTime in the WHERE clause.  This needs to be sent in the Date format (no time).
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:LionsConnectionString %>"    
        SelectCommand="SELECT ArticleID, ArticleTitle, ArticleSubject, ArticleContent, ArticleDateTime, ArticleExp, ArticleExpChkBox, UserID, UserName FROM tblLionsArticles WHERE ((ArticleDateTime) = @ArticleDateTime)">     
        <SelectParameters>    
            <asp:ControlParameter ControlID="RadDatePicker1" DefaultValue="1/1/2008" Name="ArticleDateTime"    
                PropertyName="SelectedDate" />    
        </SelectParameters>    
    </asp:SqlDataSource>   


I need to somehow accept only the Date from the calendar parameter, as well as the database understand only the date even though the SQL database has DateTime.

I having a hard time understanding how to accept only Date and SQL do a SELECT only for Date and then return only the Date value.
thanx

Deepayan

niki d
posted  220 posts
since  Oct 27, 2006 
from 

 Re: Change SelectedDate (DateTime) format
  Posted on: 11/5/2009 12:24:31 AM       

Hi Deepayan,
 
Change your select command as follows.
SELECT
ArticleID, ArticleTitle, ArticleSubject, ArticleContent, ArticleDateTime, ArticleExp, ArticleExpChkBox, UserID, UserName FROM tblLionsArticles WHERE (convert(datetime, convert(char, ArticleDateTime, 106)) = @ArticleDateTime)
 
If my answer helps you please do not forget to accept my answer.
 
Thanks
 

Niki

       
Sponsored by
Become a Sponsor
Developer-Ready ASP.NET 2.0 Web Hosting with 3 MONTHS FREE
Now supporting .NET 3.0 Framework with Windows Workflow Foundation, Windows Communication Foundation (WCF), Windows Presentation Foundation (WPF), windows CardSpace (WCS)! Providing more flexibility for Developers with Web Services Support and a User/Permission Manger. Also supporting MS SQL 2005/2000 with Real-Time Backups, FREE Automated Attach .MDF Tool, FREE SQL Restore and Shrink SQL DB Tools, and SQL
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Clickatell's SMS Gateway
Clickatell's Developer Solutions allow you to SMS enable any website or application via a range of API's. Learn More about our API connections.
Free access to .NET Memory Management video
Everything you need to know about Garbage Collection, Temporary Objects, Fragmentation, Finalization and common causes of memory leaks in .NET. Watch the video here.
Microsoft Visual Studio 2010
Microsoft Visual Studio 2010 offers more to developers than any other Visual Studio release. Work more productively and collaboratively-with greater control over your work at every step. The Beta 2 can give you a head start on achieving efficiency.

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Advertise with us
Current Version: 3.2009.8.27
 © 1999 - 2009  Mindcracker LLC. All Rights Reserved