This is a migrated thread and some comments may be shown as answers.

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

4 Answers 142 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Rahul
Top achievements
Rank 1
Rahul asked on 13 Jan 2011, 07:57 AM
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.

4 Answers, 1 is accepted

Sort by
0
Kaloyan
Telerik team
answered on 14 Jan 2011, 02:11 PM
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>>
0
Rahul
Top achievements
Rank 1
answered on 18 Jan 2011, 07:33 AM

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";
}
}

 

 

 

 

 

 

 

 

 

 

 

 

 

0
Rahul
Top achievements
Rank 1
answered on 18 Jan 2011, 11:00 AM
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";

 

}

}

0
Kaloyan
Telerik team
answered on 20 Jan 2011, 09:21 AM
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>>
Tags
DatePicker
Asked by
Rahul
Top achievements
Rank 1
Answers by
Kaloyan
Telerik team
Rahul
Top achievements
Rank 1
Share this question
or