c# - How to get minutes between two DateTimes

Minutes between two DateTimes
TotalMinutes.aspx

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e) {
        DateTime myDate1 = DateTime.Now;
        DateTime myDate2 = DateTime.Now.AddDays(2);
        TimeSpan difference = myDate2.Subtract(myDate1);

        double totalMinutes = difference.TotalMinutes;

        Label1.Text = "MyDate1: " + myDate1.ToString();
        Label1.Text += "<br />MyDate2: " + myDate2.ToString();
        Label1.Text += "<br /><br />Total Minutes Difference: " + totalMinutes;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>asp.net date time example: how to get total minutes difference between two date time object</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Navy">asp.net date time example: minutes difference</h2>
        <asp:Label 
             ID="Label1" 
             runat="server" 
             Font-Size="Larger"
             Font-Italic="true"
             Font-Bold="true"
             ForeColor="SeaGreen"
             >
        </asp:Label>
        <br /><br />
        <asp:Button 
             ID="Button1" 
             runat="server" 
             Font-Bold="true" 
             ForeColor="HotPink" 
             OnClick="Button1_Click"
             Text="Get Toatal Minutes Difference"
             />   
    </div>
    </form>
</body>
</html>
More c# examples