Hi vrindavani,
You can make use of Stopwatch which was present in System.Diagnostics namespaces.
Check this example. Now please take its reference and correct your code.
For this example i have checked with 5 seconds.
HTML
<asp:Button ID="Button1" Text="Submit" runat="server" OnClick="Submit" /><br />
Start : <asp:Label ID="lblStart" runat="server" /><br />
End : <asp:Label ID="lblEnd" runat="server" />
Namespaces
C#
using System.Diagnostics;
using System.Threading;
VB.Net
Imports System.Diagnostics
Imports System.Threading
Code
C#
protected void Submit(object sender, EventArgs e)
{
DateTime startTime = DateTime.Now;
Stopwatch stopwatch = new Stopwatch();
// Start timing.
stopwatch.Start();
int timeInSecond = 10 * 60; // 10 Minutes.
for (int i = 1; i < timeInSecond; i++)
{
Thread.Sleep(1000);
}
// Stop timing.
stopwatch.Stop();
DateTime endTime = startTime.AddSeconds(timeInSecond);
lblStart.Text = startTime.ToString("dd/MM/yyyy HH:mm:ss");
lblEnd.Text = endTime.ToString("dd/MM/yyyy HH:mm:ss");
// Code to insert start and end in Database.
}
VB.Net
Protected Sub Submit(ByVal sender As Object, ByVal e As EventArgs)
Dim startTime As DateTime = DateTime.Now
Dim stopwatch As Stopwatch = New Stopwatch()
' Start timing.
stopwatch.Start()
Dim timeInSecond As Integer = 10 * 60; ' 10 Minutes.
For i As Integer = 1 To timeInSecond - 1
Thread.Sleep(1000)
Next
' Stop timing.
stopwatch.Stop()
Dim endTime As DateTime = startTime.AddSeconds(timeInSecond)
lblStart.Text = startTime.ToString("dd/MM/yyyy HH:mm:ss")
lblEnd.Text = endTime.ToString("dd/MM/yyyy HH:mm:ss")
' Code to insert start and end in Database.
End Sub
Screenshot