Click here to Skip to main content
15,911,786 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
can any one help me in solving my problem ?


i have problem in find the date difference , i want date difference between two dates, one is coming from text box which is in format(dd/mm/yyyy)and other is coming from the Database so here is my problem while coming from data base it is having Datetime so i have to convert the date coming from text box into datetime but i am entering only date so i need to convert the date only in dateformat so is there any function to convert date into only date with date in C# here is my code.

C#
decimal LoanAmt = Convert.ToDecimal(RepayloanAmountLbl.Text);
                        int Tenure = Convert.ToInt32(RepayTenureLbl.Text);
                        DateTime RepayStartDate = Convert.ToDateTime(StartDateTxt.Text);
                        //DateTime DisbursementDate = Convert.ToDateTime(RepayDateLbl.Text);
                        DateTime DisbursementDate = Convert.ToDateTime(dt.Rows[0]["REPAY_START_DATE"].ToString());
                        TimeSpan ts = RepayStartDate.Subtract(DisbursementDate);
                        int days = ts.Days;
                        decimal Rate = Convert.ToDecimal(RepayInterestLbl.Text) / 100;
                        decimal interest = ((LoanAmt * Rate) / 365) * days;
                        decimal X = (decimal)Math.Round(interest);
                        IntAmtTxt.Text = Convert.ToString(X);
                        ActualIntLbl.Text = Convert.ToString(X);
                        PrinAmtTxt.Enabled = false;


please help me in solving the problem it is the stoper for my work
Posted
Updated 10-Feb-11 3:06am
v2

Have a look at DateTime.Date

http://msdn.microsoft.com/en-us/library/system.datetime.date.aspx[^]

// This would be date + time
DateTime now = DateTime.Now;

// This is just date
now.Date



Or there's always ToShortDateString

http://msdn.microsoft.com/en-us/library/system.datetime.toshortdatestring.aspx[^]
 
Share this answer
 
You can not convert ONLY date to DateTime. What month and year would that be? Are you sure you want to use the default month and year? You may be assuming the current month and year, are you?

If you are assuming current month and year, you could do something like this.

DateTime RepayStartDate = DateTime.Now;
RepayStartDate .Month = Convert.ToInt32(StartDateTxt.Text);
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 10-Feb-11 11:30am    
Correct, my 5.
There is a long naming tradition which is very confusing: the notion of date-time. There is no such thing, there is just time. Data is time, too. Many misunderstand.
--SA
When you have converted your text string to a DateTime object you should ensure that both contain the same time value. Setting the times in each to zero would ensure that your timespan will be a full number of days.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900