0

I have a Telerik RadDatePicker in asp.net

<telerik:RadDatePicker runat="server" Width="100px" 
                       DateInput-DateFormat="MM/dd/yyyy" 
                       DbSelectedDate='<%# Bind("FirstPosDate")%>' 
                       ID="txtFirstPosDate">
</telerik:RadDatePicker>

When I do something like:

RadDatePicker firstPosDate = ((RadDatePicker)item.FindControl("txtFirstPosDate"));
var fPosDate = firstPosDate.SelectedDate;        

I get Date and Time. Is there a way for the SelectedDate to return only the Date?

Karl Anderson
  • 34,606
  • 12
  • 65
  • 80
Nate Pet
  • 44,246
  • 124
  • 269
  • 414

2 Answers2

0

Just format the full DateTime object to the short date string via the date/time string formatters, like this:

var fPostDate = firstPosDate.SelectedDate.ToString("d");
Karl Anderson
  • 34,606
  • 12
  • 65
  • 80
  • Thanks Karl. I am using the RadDatePicker. Sorry did not mention that. I did try the .Date as you suggested but it would not take it. There is no extension of .Date – Nate Pet Nov 20 '13 at 16:11
  • Interesting, because per the Telerik documentation for [SelectedDate](http://www.telerik.com/help/sitefinity/developer-manual/radcalendar.net2-telerik.webcontrols.raddatepicker-selecteddate.html) it is a nullable .NET `DateTime` object. Does `var fPosDate = firstPosDate.SelectedDate.Value.Date;` work? – Karl Anderson Nov 20 '13 at 16:18
  • Karl, var fPosDate = firstPosDate.SelectedDate.Value.Date still shows Date and Time. Not just the Date like we like it. – Nate Pet Nov 20 '13 at 19:23
  • @NatePet - see updated answer to get just the date portion of a `DateTime` as a string. – Karl Anderson Nov 20 '13 at 19:43
0

Look at this - http://www.dotnetperls.com/datetime-format

DatePicker.SelectedDate returns a DateTime object, so you can format the object as follows (or one of the many other ways detailed in the link above):

var fPosDate = firstPosDate.SelectedDate.ToString("MM/dd/yyyy"); // Return 11/20/2013
Jon La Marr
  • 1,358
  • 11
  • 14