hi.. please check this code of mine:
protected void Button4_Click(object sender, EventArgs e)
{
DateTime dt1;
DateTime dt2;
string currenttime1 = DateTime.Now.ToLongTimeString();
string currenttime2 = DateTime.Now.ToLongTimeString();
TextBox2.Text = currenttime2;
dt1 = Convert.ToDateTime(currenttime1);
dt2 = Convert.ToDateTime(currenttime2);
TimeSpan ts = dt1 - dt2;
int hours = ts.Hours;
int min = ts.Minutes;
string finalMin = Convert.ToString(min);
TextBox3.Text = finalMin;
---- i'm having a web page that calculated time duration when the user press the stop button.. but the output of this code is always zero.. what is my error?
thanks in advance.. :)
--im using asp.net and C#
Loading
MEHA SHANMUGASUNDARAPosted May 12, 2010, 4:38 AM
currenttime1 & currenttime2 are assigned as current time. Both the time is same value. U'll use Current time is assigned to textbox1.text(when u store the start time). Then It'll Works.
If ASP.Net means store it in session or hidden value field for the start time...
Regards,
Meha
janine valenzonaPosted Apr 5, 2010, 11:20 AM
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class SUBOK : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(100);
string currenttime = DateTime.Now.ToLongTimeString();
string showDate = DateTime.Now.ToLongDateString();
lblcurrenttime.Text = currenttime;
lblshowDate.Text = showDate;
}
protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void Button3_Click(object sender, EventArgs e)
{
string currenttime1 = DateTime.Now.ToLongTimeString();
TextBox1.Text = currenttime1;
}
protected void Button4_Click(object sender, EventArgs e)
{
DateTime dt1;
DateTime dt2;
string currenttime1 = DateTime.Now.ToLongTimeString();
string currenttime2 = DateTime.Now.ToLongTimeString();
TextBox2.Text = currenttime2;
dt1 = Convert.ToDateTime(currenttime1);
dt2 = Convert.ToDateTime(currenttime2);
TimeSpan ts = dt1 - dt2;
int min = Convert.ToInt32(ts.Minutes);
string finalMin = Convert.ToString(min);
TextBox3.Text = finalMin;
}
}
---thank you sir
Sam HobbsPosted Apr 4, 2010, 12:54 PM
janine valenzonaPosted Apr 4, 2010, 10:06 AM
ahm.. the currenttime1 is from the time that was get when the START button is clicked. for example, i clicked the start button at time: 10:03 pm... so currenttime1 is: 10:03 pm... i clicked the STOP button at 11:00 pm.. currenttime2 is now 11:00.
the code i posted is just a part of the whole program sir
Sam HobbsPosted Apr 3, 2010, 2:59 PM