Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
can some one please help me out
I have a date value

date_dif.text = ((Convert.ToDateTime(date1.Text) - Convert.ToDateTime(date2.Text)).Days).ToString();

I want to multiply the difference with a figure from
example
total.text = date_dif.text * TxtQuantity.text;

when ever i do that it shows this error
Operator '*' cannot be applied to operands of type strings and strings Please how do i resolve the issue

thanks in advance
Posted

Difemeg wrote:
total.text = date_dif.text * TxtQuantity.text;
Try something like this:
C#
total.text = (double.Parse(date_dif.text) * double.Parse(TxtQuantity.text)).ToString();


Good luck,
Edo
 
Share this answer
 
Try this example which is similar to what you needed :

C#
DateTime a = new DateTime(2008, 01, 02, 06, 30, 00);
            DateTime b = new DateTime(2008, 01, 03, 06, 30, 00);
            TimeSpan duration = b - a;
            String result = TimeSpan.FromTicks(duration.Ticks * 5).ToString();


Hope this helps!
 
Share this answer
 
thank you very much It works perfectly well


C#
total.text = (double.Parse(date_dif.text) * double.Parse(TxtQuantity.text)).ToString();


However, to add currency to it like $ sign to it

C#
total.text = (double.Parse(date_dif.text) * double.Parse(TxtQuantity.text)).ToString("$" + "0.00");


the result will appear $30.00

thanks
 
Share this answer
 
Comments
Priyanka7777 12-Jul-13 1:55am    
Which solution did work for you?

Please mark the solution as answer which worked for you.
Belowing solution will help you
VB
Dim date_diff As Integer
date_diff = CInt(((Convert.ToDateTime(date1.Text) -                                        Convert.ToDateTime(date2.Text)).Days).ToString())
TextBox2.Text = date_diff * Val(TxtQuantity.Text)
 
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