Find datetime difference in asp.net by C#
How to find date difference in asp.net by C#:
In this Post we describe how to get the difference between
two DateTime value in asp.net C#.In C# code by calling any of the overloads of the DateTime
constructor that give permission you to
specify specific elements of the date and time value like year , month ,day,weekday
and current time.
DateTime newDate =
new DateTime(2000, 5, 1);
DateTime Related Other Post:
- Get current datetime in jquery and javaScript
- JQuery UI Datepicker (Calendar) with asp.net textbox
- Datetime difference in seconds
- DateTime Structure: -This datatype datatype is used to represent a time instant in C#.
- TimeSpan Structure: -The TimeSpan datatype is used to represent time interval in asp.net C#.
Calculating DateTime Difference in C#:
Use TimeSpan data type of C# for calculating difference.
TimeSpan ts = dateAfter2Minutes - now;
Calculating DateTime Difference in millisecond by C#:
int milliseconds = (int)ts.TotalMilliseconds;
Showing Difference between two datetime values in asp.net:
<%@ Page
Language="C#"
AutoEventWireup="true"
CodeFile="timediffrence.aspx.cs"
Inherits="timediffrence"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD
XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>c# example - datetime difference in milliseconds</title>
<style type="text/css">
.style1
{
font-family: Arial, Helvetica, sans-serif;
text-decoration: underline;
color: #990000;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div align="center">
<h2 class="style1">
Asp.net c# example - datetime difference
</h2>
<hr width="100%"
align="left"
color="Green"
/>
<asp:Label ID="Label1" runat="server"
Font-Size="Large"
Font-Names="Comic
Sans MS"
Style="font-family: Arial,
Helvetica, sans-serif; color: #0000FF">
</asp:Label>
<hr width="100%"
align="left"
color="Green"
/>
<br />
<br />
<asp:Button ID="Button1"
runat="server"
Text="Get
Diffrence" OnClick="Button1_Click"
Height="40px"
Font-Bold="true"
Width="112px"
/>
<hr width="100%"
align="left"
color="Green"
/>
</div>
</form>
</body>
</html>
C# code of Difference between two datetime values in asp.net:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class timediffrence
: System.Web.UI.Page
{
protected void
Page_Load(object sender, EventArgs e)
{
}
protected void
Button1_Click(object sender, EventArgs e)
{
//initialize a datetime variable with current datetime
DateTime now = DateTime.Now;
Label1.Text = "now : " +
now.ToString();
//add 2 minutes to current time
DateTime dateAfter2Minutes = now.AddMinutes(2);
TimeSpan ts = dateAfter2Minutes - now;
//total milliseconds difference between two datetime
object
int milliseconds = (int)ts.TotalMilliseconds;
Label1.Text += "<br ><br
/>after two minutes: ";
Label1.Text += dateAfter2Minutes.ToString();
Label1.Text += "<br ><br
/>smillieconds difference between to datetime object : ";
Label1.Text
+= milliseconds;
}
}
DateTime difference in asp.net by C# |
Sql Server Interview Qus:
Related Post/Reference :
- Example of Adding ToolTip for each Dropdown List Item in C#
- Limit Number of Characters in a TextArea using jQuery
- Limitation of Characters in Textbox or TextArea in asp.netusing jquery:
- jquery disable or Enable submit button after validation
- Enable Disable Submit Button using jQuery
- Get the current page url by C#
- jQuery modal dialog with postbacks
- Drag and Drop Sortable Lists using jQueryUI
- jquery tooltip with css in asp.net web page
- Ajax ColorPickerExtender in ASP.NET Example
- What is the Ajax colorpicker,How to use Ajax colorpicker
- JQuery UI Datepicker (Calendar) with asp.net textbox
- Dynamically creating aspx page,
Asp.net Related Other Post:
- Example of Adding ToolTip for each Dropdown List Item in C#
- Displaying the textbox value in javascript Messagebox
- Enable Disable Submit Button using jQuery
- jquery disable or Enable submit button after validation
- What is ASP.NET FRAMEWORK PART 1 Programming
- Display selected Date from data base into asp.net calendar
- How to create Line chart:,How to Make Data Table By C# code:
- Example of C# for Bind Data to asp.net Textbox inside gridview control
- Bind Data to asp.net textbox control in inside of gridview Using C# Example
- Example of Crystal report(Crystal_report_in asp.net programming )
- SQL Helper Class, Example of how to add captcha in Asp.net using C#
- Sql Query for asp.net Programming , How to create graph in asp.net:
- How to use CAPTCHA in asp.net,How to use Asp.net regular expression
- Display tooltip from database for dropdownlist items in asp.net c# example
- Show tooltip dropdownlist items by mouseoverevent using C# example
Comments
Post a Comment