C# code, C# Programming, C# Tutorial

[b][size=4]C# Date/Time[/size][/b]

The DateTime.Substract adjustment may be acclimated in adjustment to acquisition the date/time aberration amid two instances of the DateTime method. This method does not change the value of the DateTime instance on which the method has been invoked. The aftereffect of the operation is stored in the new TimeSpan structure.

The TimeSpan chic has a bifold set of properties, one set represents the time durations in integers and addition set of properties, with the names prefixed with "Total" represents the result in fractional values. The afterward sample cipher illustrates the use of the DateTime.Subtract adjustment and the Days and TotalDays backdrop of the TimeSpan structure.

The DateTime structure also has an overload for the Subtract method which accepts a TimeSpan and returns the DateTime value which is the result of subtracting the Timespan argument from the value of the DateTime structure on which the Subtract method has been invoked.

using System;

using System.Collections.Generic;

using System.Text;

namespace Console_DateTime


class Program


static void Main(string[] args)


System.DateTime dtTodayNoon = new System.DateTime(2006, 9, 13, 12, 0, 0);

System.DateTime dtTodayMidnight = new System.DateTime(2006, 9, 13, 0, 0, 0);

System.TimeSpan diffResult = dtTodayNoon.Subtract(dtYestMidnight);

Console.WriteLine("Yesterday Midnight - Today Noon = " + diffResult.Days);

Console.WriteLine("Yesterday Midnight - Today Noon = " + diffResult.TotalDays);





For learn more about C# plz visit on this link.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!