Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

C# DateTime tutorial

c# datetime culture parsing calculation display format

  • Please log in to reply
4 replies to this topic

#1 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts
  • Location:Argentina
  • Programming Language:C, C++, C#, PHP, JavaScript, Transact-SQL, Bash, Others
  • Learning:Java, Others

Posted 08 February 2013 - 11:09 AM

In this tutorial we will study how to work with the DateTime data type, which is crucial for reporting and business logic.

Attached Files


Edited by BlackRabbit, 24 November 2015 - 01:07 PM.

  • 1

#2 Barnsite

Barnsite

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 258 posts
  • Location:West Sussex, UK
  • Programming Language:C#, (Visual) Basic, Visual Basic .NET, Transact-SQL, Others
  • Learning:Java

Posted 15 February 2013 - 04:14 AM

Nice tutorial,

 

One other thing that you might want to add is finding the difference between two dates using TimeSpan.

 

e.g.

 

This example takes two date variables, subtract one from the other and apply the result to a TimeSpan variable, then show the results (by number of day or hours in this example).

 


DateTime dt1 = new DateTime(2013, 01, 15);
DateTime dt2 = new DateTime(2013, 02, 18);

TimeSpan ts = dt2 - dt1;
MessageBox.Show(ts.TotalDays.ToString());
MessageBox.Show(ts.TotalHours.ToString());

  • 1
There are two ways to write error-free programs; only the third one works.

#3 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts
  • Location:Argentina
  • Programming Language:C, C++, C#, PHP, JavaScript, Transact-SQL, Bash, Others
  • Learning:Java, Others

Posted 15 February 2013 - 09:44 AM

Yes, that is correct!

I didn't took it into account because I use it more like for accounting "clock" time :D , elapsing and all that jazz.

 

So, I had that knowledge "arranged" in another table in that big restaurant called my brain.


  • 0

#4 Barnsite

Barnsite

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 258 posts
  • Location:West Sussex, UK
  • Programming Language:C#, (Visual) Basic, Visual Basic .NET, Transact-SQL, Others
  • Learning:Java

Posted 18 February 2013 - 12:47 AM

You can go to that table later then  :biggrin:


  • 0
There are two ways to write error-free programs; only the third one works.

#5 DellMercant

DellMercant

    CC Lurker

  • New Member
  • Pip
  • 3 posts

Posted 13 December 2016 - 11:07 PM

Hope this will help you to kow more about...date conversion

 

Dell


  • 0





Also tagged with one or more of these keywords: c#, datetime, culture, parsing, calculation, display format