Hi Guys,
I'm try to calculate due date between two date, but I can't find how to do that in best way in C#.
I'm found the references code in VB and then I'm trying to translate that code to ASP.NET C#.
This Code in VB
'find the due date based on installments to ???
DueDate.Text = DateAdd(DateInterval.Month, Val(InstallmentsTo.Text), DateValue(RentDate.Text))
And this code I'm trying to translate in C#
private void SearchDueDate()
{
System.DateTime PaymentDate;
System.DateTime RentDate;
System.DateTime DateNow;
DateTime InstallmentsTo;
InstallmentsTo = Convert.ToDateTime(txtcicilan_ke.Text);
RentDate = Convert.ToDateTime(txttgl_pinjaman.Text);
PaymentDate = Convert.ToDateTime(txttanggal_pembayaran.Text);
txttgl_jatuh_tempo.Text = Convert.ToDateTime(PaymentDate - RentDate),InstallmentsTo.ToString("yyyy/MM/dd");
}
When I the code running get this error
Unable to cast object of type 'System.TimeSpan' to type 'System.IConvertible'.
RentDate = 2021/06/01 //yyyy/MM/dd
PaymentDate = 2021/07/01 //yyyy/MM/dd
InstallmentsTo = 1
Any help could be appriciate.