We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Can't set SelectedItem Day to 31

when I try to set the SelectedItem with a day of 31 it displays 01 any other day works fine

using this sample https://github.com/SyncfusionExamples/xamarin-sfpicker-examples

Add this to MainPage

protected override void OnAppearing()

{

ObservableCollection<object> DatesString = new ObservableCollection<object>() { "Jul", "31", "2023" };


date.SelectedItem = DatesString;

base.OnAppearing();

}

This replicates the problem

No matter which Picker I use custom SfPicker or SfDatePicker it always does thi


6 Replies 1 reply marked as answer

ET Eswaran Thirugnanasambandam Syncfusion Team April 3, 2023 01:53 PM UTC

Hi Steven,


We checked the reported problem and we discovered that it arises because the day count in the sample is determined based on the current month. For example, if the current month is April, the day count will be 30. As a result, when the selected item is provided as July 31, day 31 will be absent in the item source, so the initial item is set so that only the selected date is set July 1. By correctly mentioning the selected month in the date calculation, we can resolve the problem as mentioned in the below code snippet.

[C#]

//populate Days

int noofdays = DateTime.DaysInMonth(DateTime.Now.Date.Year, 7);


We have prepared the sample to show the correct selected date and please get the sample from the below attachment.


Regards,

Eswaran


Attachment: DateTimePicker_eef56fac.zip


ST Steven replied to Eswaran Thirugnanasambandam April 4, 2023 03:38 AM UTC

Thanks for the response.


I have an app that has repeating reminders. If the user dismisses the notification it sets the reminder for the next hour and saves it to a database, so when you open the APP the picker should display what was it the DB.

This happen on the evening and morning of March 30 - 31. at 11:30 PM 12:30 AM from what I understand since it was the same month (still March) The picker days should have populated with 31 days "the day count in the sample is determined based on the current month " all day on March 31 I could not get the picker to display March 31.


When I opened the picker it kept saying March 1 until I selected the correct day and saved it with the App open.

I tried to get your example to work to display Month, Day, Year with no hours or minutes and it didn't work. It only works if the Day is shown first. Also the Month will not be fixed but dependent on what Month the user selected

I only used July as an example to show what happens.

Do you have an example of Month, Day, Year depending on user selection?



ET Eswaran Thirugnanasambandam Syncfusion Team April 4, 2023 08:54 AM UTC

Hi Steven,


As per your requirement, we have prepared the sample to show the correct selected date in the picker with month, day, and year selections. Please get the sample and demo video from the below attachment.


Regards,

Eswaran


Attachment: DatePicker_73a5efe0.zip

Marked as answer

ST Steven replied to Eswaran Thirugnanasambandam April 4, 2023 09:14 AM UTC

YES! That works. I have been draining my brain trying to figure it out.


Thanks so much!!



PR Preethi Rajakandham Syncfusion Team April 5, 2023 05:21 AM UTC

Hi Steven,

We are glad to know that the reported problem has been resolved. Please let us know if you have any further queries on this. We will be happy to assist.

Regards,

Preethi R



ET Eswaran Thirugnanasambandam Syncfusion Team April 5, 2023 05:31 AM UTC

Hi Steven,


We are glad to hear that you have achieved your requirement. Please get in touch with us if you require any further assistance.


Regards,

Eswaran


Loader.
Up arrow icon