i have asp.net c#
computing total number of hours.
since i will pull the data from a database as a string value, i must convert that string to a datetime which seems not working at all.
the value 2015, 4, 12, 22, 28, 20 must be a string ( i will pull the data from a database in a later plan). and put that string inside "new DateTime(stringvalue)"
take a look at my code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication13
{
public partial class _Default : System.Web.UI.Page
{
DateTime now;
//string date = "2015, 4, 12, 22, 28, 20";
protected void Page_Load(object sender, EventArgs e)
{
now = new DateTime(2015, 4, 12, 22, 28, 20); // year, Month, day, hours, minutes, seconds
//now = Convert.ToDateTime(date);
}
protected void Button1_Click(object sender, EventArgs e)
{
Label3.Text = DateTime.Now.ToString();
Label2.Text = now.ToString();
TimeSpan diff = DateTime.Now - now;
double hours = diff.TotalHours;
Label1.Text = "total number of hours is: " + hours.ToString();
}
}
}