In this article I will show you how you can get the
difference of time in hours between two times using C#.Nert. It’s a console
application used for demo.
Some of my previous articles are as follows: Bind
and Retrieve ListBox Selected Value in MVC Using C#.Net, Bind
DropDownList Using Entity Framework in ASP.Net MVC Using C#, Simple
Login Form In Asp.Net Using C#.Net and VB.Net, How
to Create and Read Cookies In ASP.NET Using C#.
So for this article first we will create a new console
application and add the below code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TimeDifference
{
class Program
{
/// <summary>
/// Code to Get Time Difference Between Two Times In C#
/// </summary>
/// <param
name="args"></param>
static
void Main(string[]
args)
{
string
yourStartTime = "11:00 AM";
string
yourEndTime = "5:00 PM";
TimeSpan
durationreamin = DateTime.Parse(yourEndTime).Subtract(DateTime.Parse(yourStartTime));
Console.WriteLine("**Code to Get Time Difference Between Two Times
In C#**\n");
Console.WriteLine("Time difference : " +
durationreamin);
Console.ReadLine();
}
}
}
|
Now run the application
0 comments:
Please let me know your view