On select of Todays Date in RadDatePicker , Need to return string as "Today".

5 posts, 0 answers
  1. Rahul
    Rahul avatar
    34 posts
    Member since:
    Dec 2010

    Posted 13 Jan 2011 Link to this post

    Hi,
    I have requirement on select of Todays Date in RadDatePicker , it should return string "Today".
    Same as For Tommorows date, should return string as Tommorow.
    Is it possible such type of behaviour in Telerik.
    Please do the needul.
  2. Kaloyan
    Admin
    Kaloyan avatar
    920 posts

    Posted 14 Jan 2011 Link to this post

    Hello Rahul,

    You can use the CurrentDateTimeText to find the current selected date. The property is of the string type so you can return every possible string format. Follow the example bellow:

    <Window.Resources>
              
      
            <local:DateConverter x:Key="converter" />
      
        </Window.Resources>
      
        <Grid>
      
            <telerik:RadDatePicker x:Name="radDateTimePicker" HorizontalAlignment="Center"
                    VerticalAlignment="Center" ParseDateTimeValue="radDateTimePicker_ParseDateTimeValue" />
      
            <TextBlock
                    Text="{Binding CurrentDateTimeText, ElementName=radDateTimePicker, Converter={StaticResource converter}}"
                    HorizontalAlignment="Center" VerticalAlignment="Top" />
      
        </Grid>

    public class DateConverter : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            {
                if (value == null)
                {
                    return null;
                }
      
                DateTime date;
                if (DateTime.TryParse(value.ToString(), out date))
                {
                    if (date.Date == DateTime.Today)
                    {
                        return "Today";
                    }
                    else if (date.Date == DateTime.Today.AddDays(1))
                    {
                        return "Tommorow";
                    }
                }
                return null;
            }
      
            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            {
                return value;
            }
        }


    Greetings,
    Kaloyan
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Rahul
    Rahul avatar
    34 posts
    Member since:
    Dec 2010

    Posted 18 Jan 2011 Link to this post

    Thanks Kaloyan for the Valuable Info.

    I need here  to return a string Today in RadDateTimePicker's input box, not needed to bind to textbox.

    I implemented below logic for that but it returns Today as a String on every date select.

    It should return a string a only For Todays and Tommorows date.

    <
    telerik:RadDateTimePicker x:Name="radDateTimePicker" HorizontalAlignment="Center" VerticalAlignment="Center" ParseDateTimeValue="radDateTimePicker_ParseDateTimeValue" />

     

    private vo

     

     

    id radDateTimePicker_ParseDateTimeValue(object sender, Telerik.Windows.Controls.ParseDateTimeEventArgs args)
    {
    DateTime date = System.DateTime.Now;
    if (date.Date == DateTime.Today)
    {
    radDateTimePicker.DateTimeText =
    "Today";
    }
    else if (date.Date == DateTime.Today.AddDays(1))
    {
    radDateTimePicker.DateTimeText =
    "Tommorow";
    }
    }

     

     

     

     

     

     

     

     

     

     

     

     

     

  5. Rahul
    Rahul avatar
    34 posts
    Member since:
    Dec 2010

    Posted 18 Jan 2011 Link to this post

    Hi,
    I have fixed the issue.
    By Mistake , i took a System date .

    Here is the code

    private

     

     

    void radDateTimePicker_ParseDateTimeValue(object sender, Telerik.Windows.Controls.ParseDateTimeEventArgs args)

     

    {

     

     

    DateTime date = radDateTimePicker.DisplayDate;

     

     

     

    if (date.Date == DateTime.Today)

     

    {

    radDateTimePicker.DateTimeText =

     

    "Today";

     

    }

     

     

    else if (date.Date == DateTime.Today.AddDays(1))

     

    {

    radDateTimePicker.DateTimeText =

     

    "Tommorow";

     

    }

    }

  6. Kaloyan
    Admin
    Kaloyan avatar
    920 posts

    Posted 20 Jan 2011 Link to this post

    Hi Rahul,

    This was my idea too. The key point here is to use the ParseDateTimeValue event.

    Best wishes,
    Kaloyan
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Back to Top
UI for WPF is Visual Studio 2017 Ready