How to Compare Dates [closed]

-3

I have this code to do a save of the entered data, Day, StartDate and EndDate.

protected void btnSavePontuacao_Click(object sender, EventArgs e)
    {
        decimal id_TipoDia = 0;
        string Dia = txtDay.Text;
        string DiaInicio = txtStartDate.Text;
        string DiaFim = txtEndDate.Text;
        DateTime DtInicio, DtFim;


        if (!string.IsNullOrEmpty(Dia) && DateTime.TryParse(DiaInicio, out DtInicio))
        {
            bool result = false;
            DateTime? DtFimNullable;

            if (DateTime.TryParse(DiaFim, out DtFim))
            {
                DtFimNullable = DtFim;
            }
            else
            {
                DtFimNullable = null;
            }

            if (CheckIfRatesRangeValuesAreValid(id_TipoDia, DtInicio, DtFimNullable))
            {
                if (id_TipoDia > 0)
                {
                    result = FlowCreditTaxasProdutoExtensaoPrazoProviderManager.Provider.UpdateProdutoAmortizacaoCreditoDias(id, Dia, DiaInicio, DtFimNullable);
                }
                else
                {
                    result = FlowCreditTaxasProdutoExtensaoPrazoProviderManager.Provider.InsertProdutoAmortizacaoCreditoDias(Dia, DiaInicio, DiaFim);
                }
            }
            else
            {
                result = false;
            }

            if (result)
            {
                ShowMessageJS("sucesso");
            }
            else
            {
                ShowMessageJS("fail");
            }
        }
        else
        {
            ShowMessageJS("");
        }
    }  

No

  

CheckIfRatesRangeValuesAreValid

I'd like to know how I can do a date validation, ie if the end date is less than the start date

    
asked by anonymous 13.02.2017 / 15:22

1 answer

1

You can use the Compare Method method of DateTime link .

int result = DateTime.Compare(date1, date2);
    
13.02.2017 / 15:50