Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

C# code, C# Programming, C# Tutorial

harshkumarharshkumar Posts: 1Member
[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);

Console.ReadLine();

}

}

}

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

http://www.csharptalk.com/
Sign In or Register to comment.