- Configure database-level settings
○ Control parallelism with Max degree of parallelism (MAXDOP)
§ ALTER DATABASE SCOPED CONFIGURATION SET MAXDOP
§ The one rule: avoid MAXDOP 0 in production. Unlimited parallelism leads to resource exhaustion, query timeouts, and application outages.
§ MAXDOP 8 is the safe default
○ Let automatic tuning catch regressions
§ FORCE_LAST_GOOD_PLAN detects plan regressions and forces the previous fast plan. Enabled by default.
§ CREATE_INDEX identifies missing indexes, creates them, and verifies the improvement. Disabled by default.
§ DROP_INDEX removes unused and duplicate indexes. Disabled by default. Unique indexes, including indexes supporting primary key and unique constraints, are never dropped.
ALTER DATABASE CURRENT
SET AUTOMATIC_TUNING (FORCE_LAST_GOOD_PLAN = ON,
CREATE_INDEX = ON,
DROP_INDEX = OFF);
○ Unlock optimizer features with compatibility level
§ Each level unlocks a set of intelligent query processing (IQP) features:
□ Level 150: batch mode on rowstore, table variable deferred compilation, scalar user-defined function (UDF) inlining.
□ Level 160: parameter sensitive plan optimization (PSP), cardinality estimation feedback.
□ Level 170: optional parameter plan optimization.
§ ALTER DATABASE CURRENT SET COMPATIBILITY_LEVEL = 170;
§ Don't change this setting blindly in production. Use Query Store to capture a performance baseline at the current level, upgrade in a test environment, and compare. If a query regresses, you can force the old plan while you investigate.
○ Reduce plan cache bloat with OPTIMIZE_FOR_AD_HOC_WORKLOADS
§ ALTER DATABASE SCOPED CONFIGURATION SET OPTIMIZE_FOR_AD_HOC_WORKLOADS = ON;
§ This setting keeps the cache lean and ensures that plans for your most important queries stay resident in memory.
- Preserve data integrity with transaction isolation levels and concurrency controls
○ How isolation levels work
§ Dirty reads
§ Nonrepeatable reads
§ Phantom reads
○ SQL Server and Azure SQL Database support six isolation levels. The first four use pessimistic concurrency (locking). The last two use optimistic concurrency (row versioning).
○ Lock-based isolation levels
§ READ UNCOMMITTED is the fastest and the riskiest isolation level.
§ READ COMMITTED is the default isolation level in SQL Server and strikes a basic balance. nothing stops another transaction from changing the row between your two reads
§ REPEATABLE READ goes a step further than READ COMMITTED. It holds shared locks on every row you read until your transaction completes.
§ SERIALIZABLE takes care of everything previous levels do and more. It takes range locks that cover not just the rows you read but also the gaps between key values, blocking inserts into those ranges
○ Row-versioning isolation levels
§ Read Committed Snapshot Isolation changes the behavior of READ COMMITTED at the database level. RCSI is enabled by default in Azure SQL Database
§ SNAPSHOT isolation takes this solution a step further. Instead of a per-statement snapshot, each read sees the data as it existed at the start of the entire transaction.
□ you must enable ALLOW_SNAPSHOT_ISOLATION on the database and set the isolation level explicitly in the session
○ Reduce blocking with optimized locking
§ Transaction ID (TID) locking: Instead of holding individual key or row locks for every modified row, the engine takes a single exclusive lock on the transaction ID (TID).
§ Lock after qualification: Before a row is modified, the engine reads the latest committed version without acquiring a lock and checks whether the row matches the query predicate.
○ Choose the right isolation level
- Evaluate query performance with execution plans and DMVs
○ Read execution plans
§ Estimated execution plan: Generated without running the query. It shows the planned operators and estimated row counts based on statistics. Use estimated plans for quick analysis without affecting the database.
§ Actual execution plan: Captured during query execution. It includes the estimated plan plus real row counts, actual execution times, memory grants, and warnings. The actual plan reveals discrepancies between what the optimizer expected and what actually happened.
○ Identify common issues in execution plans
○ Query DMVs for runtime performance data
§ Find the most expensive queries
SELECT TOP 10
qs.total_worker_time / qs.execution_count AS avg_cpu_time,
qs.execution_count,
qs.total_logical_reads / qs.execution_count AS avg_logical_reads,
SUBSTRING(st.text, (qs.statement_start_offset / 2) + 1,
((CASE qs.statement_end_offset
WHEN -1 THEN DATALENGTH(st.text)
ELSE qs.statement_end_offset
END - qs.statement_start_offset) / 2) + 1) AS query_text
FROM sys.dm_exec_query_stats AS qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS st
ORDER BY avg_cpu_time DESC;
□ High avg_logical_reads relative to the result set size often points to missing indexes or inefficient plans
§ Check currently executing queries
SELECT
r.session_id,
r.status,
r.command,
r.wait_type,
r.wait_time,
r.blocking_session_id,
r.cpu_time,
r.logical_reads,
t.text AS query_text
FROM sys.dm_exec_requests AS r
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) AS t
WHERE r.session_id > 50
ORDER BY r.cpu_time DESC;
§ Discover missing indexes
SELECT
mid.statement AS table_name,
mid.equality_columns,
mid.inequality_columns,
mid.included_columns,
migs.avg_total_user_cost * migs.avg_user_impact *
(migs.user_seeks + migs.user_scans) AS improvement_measure
FROM sys.dm_db_missing_index_groups AS mig
INNER JOIN sys.dm_db_missing_index_group_stats AS migs
ON migs.group_handle = mig.index_group_handle
INNER JOIN sys.dm_db_missing_index_details AS mid
ON mig.index_handle = mid.index_handle
ORDER BY improvement_measure DESC;
□ This query calculates an improvement_measure for each missing index recommendation, which is a product of the average cost of queries that would benefit from the index, the average percentage improvement, and the number of times those queries were executed
§ Monitor active sessions and waiting tasks
□ sys.dm_exec_sessions
□ sys.dm_os_waiting_tasks
§ Execution plans and DMVs give you a complete picture of query behavior. Start with DMVs to identify the most expensive queries. Then drill into their execution plans to understand why they're expensive. Is it a missing index causing a scan? Outdated statistics causing row estimate errors? A Key Lookup you can eliminate? This systematic approach, from system-wide view to individual query analysis, is the most efficient way to find and fix performance bottlenecks.
- Monitor and tune queries with Query Store and Query Performance Insight
○ Understand Query Store architecture
○ Detect regressed queries
§ In SSMS, expand the database node in Object Explorer. Expand the Query Store folder. Select Regressed Queries.
§ Top Resource Consuming Queries: Shows the queries with the highest resource usage for a chosen metric and time range. This report is the most common starting point for day-to-day performance tuning.
§ Queries With High Variation: Surfaces queries whose performance fluctuates significantly, which often indicates parameter sensitivity or varying data distributions.
§ Queries With Forced Plans: Lists all currently forced plans so you can review and manage them.
§ Query Wait Statistics: Groups wait statistics by category and show which queries contribute to each wait type.
○ Query the Query Store with T-SQL
SELECT TOP 10
qt.query_sql_text,
q.query_id,
p.plan_id,
ROUND(CONVERT(FLOAT, SUM(rs.avg_duration * rs.count_executions))
/ NULLIF(SUM(rs.count_executions), 0), 2) AS avg_duration,
SUM(rs.count_executions) AS total_executions
FROM sys.query_store_query_text AS qt
INNER JOIN sys.query_store_query AS q
ON qt.query_text_id = q.query_text_id
INNER JOIN sys.query_store_plan AS p
ON q.query_id = p.query_id
INNER JOIN sys.query_store_runtime_stats AS rs
ON p.plan_id = rs.plan_id
WHERE rs.last_execution_time > DATEADD(HOUR, -1, GETUTCDATE())
GROUP BY qt.query_sql_text, q.query_id, p.plan_id
ORDER BY avg_duration DESC;
○ Force a plan
§ When you identify that a previous plan was better, you can tell the optimizer to use that specific plan for future executions.
§ To Force Plan - EXEC sp_query_store_force_plan @query_id = 42, @plan_id = 17;
§ To unforce a plan - EXEC sp_query_store_unforce_plan @query_id = 42, @plan_id = 17;
○ Apply Query Store hints
§ to limit a query to a single thread - EXEC sp_query_store_set_hints @query_id = 42, @query_hints = N'OPTION (MAXDOP 1)';
§ force a recompile on every execution - EXEC sp_query_store_set_hints @query_id = 42, @query_hints = N'OPTION (RECOMPILE)';
§ combine multiple hints in a single call - EXEC sp_query_store_set_hints @query_id = 42, @query_hints = N'OPTION (MAXDOP 1, MAX_GRANT_PERCENT = 10)';
§ To remove a hint: EXEC sp_query_store_clear_hints @query_id = 42;
○ Analyze wait statistics per query
ALTER DATABASE CURRENT
SET QUERY_STORE (WAIT_STATS_CAPTURE_MODE = ON);
○ Monitor with Query Performance Insight
○ Follow best practices
- Identify and resolve blocking and deadlocks
○ Blocking
○ Identify blocking chains
SELECT
r.session_id,
r.blocking_session_id,
r.wait_type,
r.wait_time,
r.wait_resource,
t.text AS query_text,
r.status,
r.command
FROM sys.dm_exec_requests AS r
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) AS t
WHERE r.blocking_session_id <> 0
ORDER BY r.wait_time DESC;
○ Recognize common blocking scenarios
§ A long-running query that holds locks for an extended period
§ A sleeping session with an uncommitted transaction
§ A session that didn't fetch all result rows
§ A session in a rollback state
§ An orphaned connection
○ Resolve active blocking
§ When you find active blocking:
□ Identify the head blocker using the DMV query shown earlier.
□ Determine whether the blocking session's transaction can finish on its own or whether it's waiting on external input.
□ If the blocking session is an orphaned or abandoned connection, terminate it with KILL <session_id>;
□ Review the blocking query's execution plan for optimization opportunities such as missing indexes.
○ Deadlocks
§ A deadlock occurs when two or more transactions form a circular dependency
○ Capture deadlock information
-- Create and start the session
CREATE EVENT SESSION [deadlocks] ON DATABASE
ADD EVENT sqlserver.database_xml_deadlock_report
ADD TARGET package0.ring_buffer
WITH (STARTUP_STATE = ON, MAX_MEMORY = 4 MB);
GO
ALTER EVENT SESSION [deadlocks] ON DATABASE STATE = START;
GO
-- Query deadlock events from the ring buffer
DECLARE @tracename sysname = N'deadlocks';
SELECT
d.value('(/event/@timestamp)[1]', 'datetime2') AS deadlock_time,
d.query('/event/data[@name=''xml_report'']/value/deadlock') AS deadlock_xml
FROM (
SELECT CAST(target_data AS XML) AS rb
FROM sys.dm_xe_database_sessions AS s
INNER JOIN sys.dm_xe_database_session_targets AS t
ON CAST(t.event_session_address AS BINARY(8)) = CAST(s.address AS BINARY(8))
WHERE s.name = @tracename
AND t.target_name = N'ring_buffer'
) AS ring_buffer
CROSS APPLY rb.nodes(
'/RingBufferTarget/event[@name=''database_xml_deadlock_report'']'
) AS xevent(d)
ORDER BY deadlock_time DESC;
○ Prevent deadlocks
§ Access objects in a consistent order
§ Keep transactions short
§ Use row-versioning isolation levels
§ Add appropriate indexes
§ Use plan forcing with Query Store
○ Handle deadlocks in application code
BEGIN TRY
BEGIN TRANSACTION;
-- Your data modification statements
COMMIT TRANSACTION;
END TRY
BEGIN CATCH
IF ERROR_NUMBER() = 1205
BEGIN
ROLLBACK TRANSACTION;
WAITFOR DELAY '00:00:01'; -- Brief pause before retry
-- Retry logic here
END
ELSE
BEGIN
ROLLBACK TRANSACTION;
THROW;
END
END CATCH;
Optimize Database Performance
Posted by Viral Sarvaiya on March 5, 2026
Posted in ASP.NET | Tagged: ai, artificial-intelligence, database, SQL, technology | Leave a Comment »
Getting Started with AWS Lambda and C#
Posted by Viral Sarvaiya on December 26, 2017
I know its very late to write about AWS Lambda but i just learned AWS and writing vary basic things on AWS lambda.
What is Lambda?
First of all we need to know what is AWS lambda.
Lambda is compute service provided by Amazon web service that let you run your code without managing servers. if you like to create small bunch of code or simple function that works for you into AWS Lambda.
You can run code for virtually any type of application or backend service – all with zero administration.
All we need to do is supply your code in one of the languages that AWS lambda supports. Currently AWS Lambda supports Node.js, Java, Python and C#.
Prerequisites to Create New Lambda Function using Visual Studio and C#.
To create AWS lambda function we have following Prerequisites
– Visual Studio 2015 SP1 or Visual Studio 2017 and .Net core for windows installed. ( Dotnet core – https://www.microsoft.com/net/download/windows)
– Toolkit for Visual Studio. – https://aws.amazon.com/visualstudio/
– Then we need to specify our credentials into AWS Explorer of Visual Studio.
○ After installing AWS toolkit it enables option of AWS Explorer into Visual studio -> View menu as below image.
It will open AWS Explorer.
○ Click to new Account Profile and it will open below popup.
Add your AWS account’s Access key ID, Secret Access Key or you can import CSV file exported from AWS while creating user. Then click to OK at last.
Create New Lambda function using Visual Studio.
Now we are creating new project for AWS lambda function.
– File Menu -> New -> Project, it will open new project selection popup.
Select Installed pane from left side and choose AWS Lambda and then choose project type as “AWS Lambda Project (.Net Core).
– After you select project type choose Blueprint, here we will choose Empty function.
It will open default template for Lambda function, Listed all files as displayed into Solution explorer.
And Function.cs file will have as below code default.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Amazon.Lambda.Core;
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
namespace AWSLambdaTest
{
public class Function
{
/// <summary>
/// A simple function that takes a string and does a ToUpper
/// </summary>
/// <param name="input"></param>
/// <param name="context"></param>
/// <returns></returns>
public string FunctionHandler(string input, ILambdaContext context)
{
return "Hello from Lambda!" + " - " + DateTime.UtcNow;
}
}
}
We can modify as per our need, we can also modify Class Name, Function Handler name.
Here I am updating Class Name = LambdaTestFunction
And Function name = LamndaDemoHandler
Body of function I am keeping as it is.
Publish to Lambda
– In solution explorer, right click to Lambda project and choose “Publish to AWS Lambda”
– It will open “Upload Lambda function” window.
– We need to confirm Account profile to use and its region where we like to upload our Lambda function.
– If you are creating new Lambda function then write name into textbox or select existing Lambda function from same dropdown.
– Configuration will be “Release”
– Framework = “netcoreapp1.0”
– Assembly Name will be namespace of our Lambda project. Here for us it will AWSLambdaTest
– Type Name will be namespace.class name, here for us AWSLambdaTest.LambdaTestFunction
– Method Name will be handler name, here for us LamndaDemoHandler
– If you like to save settings then we can check checkbox
– Click to Next for selecting Role and other configuration.
– Require Role name, you can choose existing role which has access policy to upload Lambda function. Or create new Role to upload lambda function.
– If your Lambda function accesses resources on Amazon VPC then select VPC subnets.
– Set environment variables if your lambda function require. Keys will be automatically encrypted by default service key.
– Choose “Upload”
– It will upload Lambda function and automatic close when upload completes.
– After function uploads it open Function page, use left tabs to test your lambda function, add event source, and view logs.
– You can add subnet into Configuration tab.
– Event sources tab is used if other source you have used, like Dynamo DB or etc.
– Logs will display Logs for Lambda function.
– From example Request dropdown you can choose your requests, here we are selecting “hello World” and typing string because our lambda function accepts string only.
– After completing all configuration click to “invoke” and it will call our lambda function and display result into Response box and you can check log into log box.
Now your lambda function is created and tested and ready for use.
Thanks.
Ref – http://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/lambda-index.html
Posted in .Net, asp.net feature, AWS, AWS Lambda, C#, Lambda Function, netcore | Tagged: .net, .net Core, Amazon, Amazon web service, AWS, AWS Lambda, C#, cloud, Dotnet core, Lambda, Lambda Funcation, netcoreapp1.0, serverless | Leave a Comment »
SOLID Principles C#
Posted by Viral Sarvaiya on August 7, 2017
I know i am very very late in getting knowledge of this powerful principles but this is very nice article for getting knowledge of SOLID Principles for creating architecture of your project.
S: Single Responsibility Principle (SRP)
O: Open closed Principle (OSP)
L: Liskov substitution Principle (LSP)
I: Interface Segregation Principle (ISP)
D: Dependency Inversion Principle (DIP)
here is some nice articles which explains in simple words and with examples.
https://www.codeproject.com/Articles/703634/SOLID-architecture-principles-using-simple-Csharp
http://www.c-sharpcorner.com/UploadFile/damubetha/solid-principles-in-C-Sharp/
Thank you!
Posted in .Net, Architect, C#, SOLID Principles | Leave a Comment »
LINQ expressions with javaScript!
Posted by Viral Sarvaiya on April 7, 2015
Hello All, after a long time..
I get very useful link which I like to share with you all.
Being a web developer and using javaScript everyday, Now more than ever javaScript is exploding in its usage.
we can use linq in javascipt. surprised? click here to learn more about that.
Thanks.
Posted in ASP.NET, Javascript | Tagged: Javascript, linq | Leave a Comment »
Using Jquery detect mobile
Posted by Viral Sarvaiya on October 22, 2013
Toay i get good script of jQuery that detect mobile.
It require to Jquery file – http://code.jquery.com/jquery-1.8.3.js
Here code is.
$(document).ready(function () {
var isMobile = {
Android: function () {
return navigator.userAgent.match(/Android/i) ? true : false;
},
BlackBerry: function () {
return navigator.userAgent.match(/BlackBerry/i) ? true : false;
},
iOS: function () {
eturn navigator.userAgent.match(/iPhone|iPad|iPod/i) ? true : false;
},
Windows: function () {
return navigator.userAgent.match(/IEMobile/i) ? true : false;
},
any: function () {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows());
}
};
alert(isMobile.any())
});
Hope it helps you.
Thanks.
Posted in Javascript, Jquery | Tagged: detect mobile, Javascript, Jquery, Jquery detect mobile, Using Jquery detect mobile | Leave a Comment »
Export to Excel using jQuery
Posted by Viral Sarvaiya on October 21, 2013
From my past posts explains how to export to excel as
1. Export GridView Data into CSVFile In Asp.net
2. GridView Export to Excel
So here its 3rd type to export to excel using Jquery.
In javascript, we have window.open function. We are using same function to export to excel using jquery.
Syntax,
window.open(MIMEtype,replace);
Here
MIMEtype : this is the optional parameter, and its for type of document. default it take as “text/html”
replace : this is also optional parameter, and its set.
Example,
$("#btn_Export").click(function(e) {
window.open('data:application/vnd.ms-excel,' + $('#divData').html());
e.preventDefault();
});
Hope its helps you.
Thanks.
Posted in .Net, ASP.NET, Javascript, Jquery | Tagged: export gridview, Export to excel, Export to Excel using jQuery, Javascript, Jquery, window.open | Leave a Comment »
Convert data from Generic List to DataTable.
Posted by Viral Sarvaiya on May 9, 2013
Today i am sharing very good a function which convert all Generic list’s data to Datatable is as below
public DataTable LINQToDataTable<T>(IEnumerable<T> varlist)
{
DataTable dtReturn = new DataTable();
// column names
PropertyInfo[] oProps = null;
if (varlist == null) return dtReturn;
foreach (T rec in varlist)
{
// Use reflection to get property names, to create table, Only first time, others will follow
if (oProps == null)
{
oProps = ((Type)rec.GetType()).GetProperties();
foreach (PropertyInfo pi in oProps)
{
Type colType = pi.PropertyType;
if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition() == typeof(Nullable<>)))
{
colType = colType.GetGenericArguments()[0];
}
dtReturn.Columns.Add(new DataColumn(pi.Name, colType));
}
}
DataRow dr = dtReturn.NewRow();
foreach (PropertyInfo pi in oProps)
{
dr[pi.Name] = pi.GetValue(rec, null) == null ? DBNull.Value : pi.GetValue(rec, null);
}
dtReturn.Rows.Add(dr);
}
return dtReturn;
}
Hope this will helps you.
Thanks.
Posted in .Net, C#, General, LINQ | Tagged: .net, C#, Convert iEnumerable to DataTable, Convert iQueryable to DataTable, dataset, datatable, Generic List, ienumerable, IList, iqueryable, linq | Leave a Comment »
Find Difference between 2 dates in Year, month, day, hour, minute, second and millisecond.
Posted by Viral Sarvaiya on May 3, 2013
After a long time i get time to post in my blog.
Few day ago i get very good function which finds difference between 2 dates.
Below is the class named “DateTimeSpan.cs”
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
public struct DateTimeSpan
{
private readonly int m_years;
private readonly int m_months;
private readonly int m_days;
private readonly int m_hours;
private readonly int m_minutes;
private readonly int m_seconds;
private readonly int m_milliseconds;
public DateTimeSpan(int years, int months, int days, int hours, int minutes, int seconds, int milliseconds)
{
this.m_years = years;
this.m_months = months;
this.m_days = days;
this.m_hours = hours;
this.m_minutes = minutes;
this.m_seconds = seconds;
this.m_milliseconds = milliseconds;
}
public int Years
{
get { return m_years; }
}
public int Months
{
get { return m_months; }
}
public int Days
{
get { return m_days; }
}
public int Hours
{
get { return m_hours; }
}
public int Minutes
{
get { return m_minutes; }
}
public int Seconds
{
get { return m_seconds; }
}
public int Milliseconds
{
get { return m_milliseconds; }
}
private enum Phase
{
Years,
Months,
Days,
Done
}
public static DateTimeSpan CompareDates(DateTime date1, DateTime date2)
{
if (date2 < date1)
{
dynamic sub = date1;
date1 = date2;
date2 = sub;
}
DateTime current = date1;
int years = 0;
int months = 0;
int days = 0;
Phase phase__1 = Phase.Years;
DateTimeSpan span = new DateTimeSpan();
while (phase__1 != Phase.Done)
{
switch (phase__1)
{
case Phase.Years:
if (current.AddYears(years + 1) > date2)
{
phase__1 = Phase.Months;
current = current.AddYears(years);
}
else
{
years += 1;
}
break; // TODO: might not be correct. Was : Exit Select
break;
case Phase.Months:
if (current.AddMonths(months + 1) > date2)
{
phase__1 = Phase.Days;
current = current.AddMonths(months);
}
else
{
months += 1;
}
break; // TODO: might not be correct. Was : Exit Select
break;
case Phase.Days:
if (current.AddDays(days + 1) > date2)
{
current = current.AddDays(days);
dynamic timespan = date2 - current;
span = new DateTimeSpan(years, months, days, timespan.Hours, timespan.Minutes, timespan.Seconds, timespan.Milliseconds);
phase__1 = Phase.Done;
}
else
{
days += 1;
}
break; // TODO: might not be correct. Was : Exit Select
break;
}
}
return span;
}
}
Now in default.aspx page i am using this structure to get difference between 2 dates as below.
protected void Page_Load(object sender, EventArgs e)
{
DateTimeSpan datetimespan = new DateTimeSpan(); // Create object of constructer to get difference.
string date1 = "3-May-2013 9:26:10.011 AM"; //Date 1
string date2 = "4-June-2014 6:50:20.136 PM"; // date2
datetimespan = DateTimeSpan.CompareDates(Convert.ToDateTime(date1), Convert.ToDateTime(date2)); //Call static function of DateTimeSpan structure. which return difference of 2 dates.
Response.Write("Date 1 : " + date1 + " <br>");
Response.Write("Date 2 : " + date2 + " <br><br>");
Response.Write("Years : " + datetimespan.Years + "<br>");
Response.Write("Months : " + datetimespan.Months + "<br>");
Response.Write("Days : " + datetimespan.Days + "<br>");
Response.Write("Hours : " + datetimespan.Hours + "<br>");
Response.Write("Minutes : " + datetimespan.Minutes + "<br>");
Response.Write("Seconds : " + datetimespan.Seconds + "<br>");
Response.Write("Milliseconds : " + datetimespan.Milliseconds + "<br>");
}
This will give difference in all possible ways as below output.
Hope this will helps you.
Thanks.
Posted in .Net, C#, General | Tagged: date, Date difference, DateTime, Find Difference between 2 dates, millisecond, minute, Month, time, Year | Leave a Comment »















