Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Addition of days to fromDate

AishwaryaKAishwaryaK INMember ✭✭

How to add number of days to fromDate in datepicker based on number of days selected in a picker.Also after adding the days the previous dates should be disabled.Please help me with the answer.

Answers

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @AishwaryaK You can do it as follows:

    DateTime fromDate = datepickerFromDate.Date;
    int numDays = Convert.ToInt32(entryNumDays.Text);
    DateTime toDate = fromDate.AddDays(numDays);
    datepickerToDate.Date = toDate;
    
    datepickerFromDate.IsEnabled = false;
    entryNumDays.IsEnabled = false;
    

    Hope this helps.

  • AishwaryaKAishwaryaK INMember ✭✭

    @ShantimohanElchuri
    can you please tell me the definition for the method AddDays(); ?

  • AnupaAnupa INMember ✭✭

    @ShantimohanElchuri

    private async void Button_Clicked(object sender, EventArgs e)
    {
    try
    {
    loginResponseModel.UserName = username.Text;
    loginResponseModel.Password = password.Text;
    // var result = await ApiClass.GetAsyncMethod(ApiClass.login);
    // loginResponseModel = JsonConvert.DeserializeObject(result);
    if (string.Equals(loginResponseModel.UserName, username) && string.Equals(loginResponseModel.Password, password))
    await DisplayAlert("Login", "Login Successful", "OK");

            }
            catch (Exception ex)
            { }
            //  await Navigation.PushAsync(new LeaveForm());
        } 
    

    This is my Button Click Code ,I have used GetMethod in Api .When I click login button its not going to next page and its not taking Api values.please help me where I have went wrong.Give me the solution.

  • AnupaAnupa INMember ✭✭

    Atleast popup message is not showing.Please tell me.

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @AishwaryaK said:
    @ShantimohanElchuri
    can you please tell me the definition for the method AddDays(); ?

    Here is the System.DateTime.AddDays Method details.

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @Anupa said:
    @ShantimohanElchuri

    private async void Button_Clicked(object sender, EventArgs e)
    {
    try
    {
    loginResponseModel.UserName = username.Text;
    loginResponseModel.Password = password.Text;
    // var result = await ApiClass.GetAsyncMethod(ApiClass.login);
    // loginResponseModel = JsonConvert.DeserializeObject(result);
    if (string.Equals(loginResponseModel.UserName, username) && string.Equals(loginResponseModel.Password, password))
    await DisplayAlert("Login", "Login Successful", "OK");

            }
            catch (Exception ex)
            { }
            //  await Navigation.PushAsync(new LeaveForm());
        } 
    

    This is my Button Click Code ,I have used GetMethod in Api .When I click login button its not going to next page and its not taking Api values.please help me where I have went wrong.Give me the solution.

    First, your question is not related to the topic of this thread.

    From how you set the loginResponseModel.UserName your could should not be compiling. However may be the following will be acceptable.

    if (string.Equals(loginResponseModel.UserName, username.Text)
        && string.Equals(loginResponseModel.Password, password.Text))
        await DisplayAlert("Login", "Login Successful", "OK");
    

    But remember that DisplayAlert is method of the Page object. If you are using this code in a class, then you have to ensure a Page object is available at that point.

    If what I suggested didn't work, open a new thread with your question.

  • AnupaAnupa INMember ✭✭

    how to deserialize an object in get method

  • AishwaryaKAishwaryaK INMember ✭✭

    @ShantimohanElchuri That code didnt work.Do you know any other solution?

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @AishwaryaK said:
    @ShantimohanElchuri That code didnt work.Do you know any other solution?

    Post your code segment to help you out.

  • AishwaryaKAishwaryaK INMember ✭✭

    @ShantimohanElchuri -

    public void LeaveDate()
    {
    try
    {
    DateTime fromDate = fromdate.Date;
    applyLeaveRequestModel.Count = leavedays.Items[leavedays.SelectedIndex];
    int numDays = Convert.ToInt32(applyLeaveRequestModel.Count);
    DateTime toDate = fromDate.AddDays(numDays);
    todate.Date = toDate;
    fromdate.IsEnabled = false;
    }
    catch(Exception ex)
    { }
    }

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @AishwaryaK Was it throwing an error or just not behaving as you wanted?

  • mcourtermcourter Member ✭✭

    property or indexer 'DateTime.Date' cannot be assigned -- It is readonly.

  • Ashish_sharmaAshish_sharma INMember ✭✭✭

    Hello is there any idea to decrease current date form xaml?
    because in my xmal page label have bind and want to use in the another able by decrease one date from current date .

    Thanks

Sign In or Register to comment.