DateTime Deep Dive in C# plus DateOnly and TimeOnly in .NET 6

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 พ.ย. 2024

ความคิดเห็น • 67

  • @mrsajjad30
    @mrsajjad30 3 ปีที่แล้ว +7

    This is it. My search for date-time tutorials ends here. Thank you Mr. Corey.

  • @torgeirullestad3921
    @torgeirullestad3921 3 ปีที่แล้ว +2

    This video should have been made 5 years ago or before Took me forever to learn this stuff back then. Glad to see that someone finally made a good deep dive into this.

    • @IAmTimCorey
      @IAmTimCorey  3 ปีที่แล้ว +2

      Hopefully it will help someone else who was in your shoes five years ago.

  • @BogLungu
    @BogLungu 3 ปีที่แล้ว

    Tim ! Fantastic topic ! Please keep in mind! A video like this for “multi trading “ will be incredibly!

    • @IAmTimCorey
      @IAmTimCorey  3 ปีที่แล้ว

      I will add it to the list. Thanks for the suggestion.

  • @torrvic1156
    @torrvic1156 9 หลายเดือนก่อน

    Excellent video! Especially I loved a part about how to convert DateTime to different formats. Wish that someday you’ll make a video about how to store DateTime in databases properly and how to convert them properly to store this values in a database. I have a hunch that it is a bad practice to use varchar for column in relational database to store DateTime info there. It should be timestamptz I guess. So much stuff to learn here. I am sure that Mr.Corey is the best one who can unveil this mystery for us.

    • @IAmTimCorey
      @IAmTimCorey  9 หลายเดือนก่อน

      Thanks for the suggestion. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/

  • @attilaguba856
    @attilaguba856 3 ปีที่แล้ว

    Exactly that's what I've been searching for long time! Thank You !

    • @IAmTimCorey
      @IAmTimCorey  3 ปีที่แล้ว +1

      You are welcome.

    • @attilaguba856
      @attilaguba856 3 ปีที่แล้ว

      @@IAmTimCorey hey! Could you make a tutorial about asp net mvc Identity Login, Registration, Reset and Forget password, Role based stuff etc , I'd buy it 😊

  • @digitallight8113
    @digitallight8113 ปีที่แล้ว

    Thanks Tim! Awesome video about Datetime

  • @getimad1076
    @getimad1076 2 ปีที่แล้ว

    Man I really enjoyed this tutorial. Thank You ❤

  • @d3tn3tracer
    @d3tn3tracer 3 ปีที่แล้ว

    Thank you for nice course Mr. Corey! :) Now I can be DateTime master. Nice explained it for me.

  • @klearner666
    @klearner666 2 ปีที่แล้ว

    Please make a video off DateTimeOffSet with it's all details.
    Including how to get it from view.
    Correct way of storing it in db, retriving them,filtering them
    All the best real world practises

    • @IAmTimCorey
      @IAmTimCorey  2 ปีที่แล้ว

      Thanks for the suggestion. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/

  • @OliverKlacik
    @OliverKlacik 2 ปีที่แล้ว

    Hi Tim. Good video, but I must point out that using predefined formats to print out DateTime depends on local Date & Time settings, so it would print out different formats for US and some country from Europe. It can also work perfectly on local machine and get messed up when deployed. That's why custom formats are better, because they are more predictable.

    • @IAmTimCorey
      @IAmTimCorey  2 ปีที่แล้ว

      Printing out different formats is typically a feature, not a bug. If I print out the date 10/8/22, people in the US will say that is October 8th whereas people in Europe will say that is August 10th. If I forced the date to print in one format, I would misinform a major group of people. By allowing it to print in a local format, we avoid these issues.

    • @OliverKlacik
      @OliverKlacik 2 ปีที่แล้ว

      @@IAmTimCorey My apologies Tim, I wasn't clear enough. For single app UI in different regions that is perfectly valid and you are 100% correct. But on the backend it can cause issues. Let's say formatting date/time for logs, exporting CSV/TXT files that should be parsed by some other app or simply creating a local website for a single country. Works fine on local machine, but once deployed to server formatting is based on the setting on server OS, which you might not be able to control. I've mentioned this because I did face this issue few times throughout my career.
      Your videos are really good. You have a way of explaining things that's fun to watch even for seasoned developers. I've seen a lot of your videos and for me personally the best ones are when you are teaching architecture. Keep going, and thank you for putting this out there.

  • @latinofac1981
    @latinofac1981 3 ปีที่แล้ว

    As usual.. great content! Thank you for sharing!

  • @tosinakinyemi3948
    @tosinakinyemi3948 2 ปีที่แล้ว

    This is insightful, thank you Tim, i will very much love it if you make DateTime Offset video too. once again thank you to the big kahuna of C#...lol am just messing with you Tim but you're the bomb.

  • @alfonsdeda8912
    @alfonsdeda8912 ปีที่แล้ว

    Hi Tim, thanks for explanation.
    I have two questions:
    -single letters formats like d D o ecc. avoid to specify the invariantCulture?
    -Should I put always culture info.invariantculture when I read or write to a file a datetime?
    Thanks in advance.

  • @yerkebulanserikbayev4736
    @yerkebulanserikbayev4736 2 ปีที่แล้ว +1

    Thank you Mr. Corey! Another great tutorial. Can you please create video about DateTimeOffset type ;)

    • @IAmTimCorey
      @IAmTimCorey  2 ปีที่แล้ว

      Thanks for the suggestion. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/

  • @aovtv6477
    @aovtv6477 2 ปีที่แล้ว

    Hi Tim,
    Is it a plug in in visual studio that show descriptive text of format date formats , method and funtions?

  • @everabyss
    @everabyss ปีที่แล้ว

    Good job!

  • @BogLungu
    @BogLungu 3 ปีที่แล้ว

    This is fantastic! Thank you!

  • @amirmehdihosseini
    @amirmehdihosseini 3 หลายเดือนก่อน

    nice job. helpful.

    • @IAmTimCorey
      @IAmTimCorey  3 หลายเดือนก่อน

      I am glad it was helpful.

  • @michaelschneider603
    @michaelschneider603 3 ปีที่แล้ว

    So it looks like DateTime's minimal value is the 1st of January of year 1. How then would I write an Asterix game in .NET, which dates back to 50 BC? :-)

  • @pierreplourde
    @pierreplourde 2 ปีที่แล้ว

    Given the value of DateTime.MaxValue, does that mean that C# won’t be affected by the Year 2038 problem?

    • @IAmTimCorey
      @IAmTimCorey  2 ปีที่แล้ว +1

      Not in that specific instance.

  • @uppercat7268
    @uppercat7268 3 ปีที่แล้ว

    tim the time traveler teaches timespan things :)

  • @scwyldspirit
    @scwyldspirit 3 ปีที่แล้ว

    Hey Tim are you planning on going over the dependency injection in Dotnet 6?

  • @alekseev74
    @alekseev74 3 ปีที่แล้ว

    Hello. Could you make a video about Nullable Reference Types with Entity Framework Core? There are usage tricks that do not fit the default rules.

  • @maciekJazzy
    @maciekJazzy 3 ปีที่แล้ว

    Thanks man!!!

  • @LifeWithSeb99
    @LifeWithSeb99 3 ปีที่แล้ว +1

    Are we gonna get black Friday discounts on your courses, Tim? 😆

  • @azgan123
    @azgan123 3 ปีที่แล้ว

    Can you make a course about how to use c/cpp API in c#? I'll pay!

  • @gdenzilg
    @gdenzilg 3 ปีที่แล้ว

    I have noticed that you recommend Devs to not use EF-Core Magic and instead write their own DML to database, e.g. Direct Queries and Stored Procedures. the question is, with EF Core, i can create a In-Memory Database for Testing, now my App is heavily Stored Procedures dependent, how to i test those with In-Memory Database, that is if at all possible?

    • @torrvic1156
      @torrvic1156 9 หลายเดือนก่อน

      No. He never recommended not to use EF stuff. He told that you’ll have to be really knowledgeable to use it. And he never told to use direct queries to database. Quite an opposite. He recommends to use stored procedures whenever it is possible.

  • @davidwhite2011
    @davidwhite2011 3 ปีที่แล้ว

    Lets say all I know is that today is November 8th, 2021 but I get a date of January 8th no year. What is the best way to know to also increment the year as January is into the next year. I guess I could get the days different between January 8th,2021 and January 8th,2022 and take the lesser but I think maybe I am missing an easier way?

    • @henry-js
      @henry-js 3 ปีที่แล้ว +1

      You could do date.AddMonths(1) until date is equal to January 8th 2021

  • @andywalter7426
    @andywalter7426 3 ปีที่แล้ว

    I checked out the nodatime. That seems to be much harder than the standard date/time. Its easy enough for people to create extensions to make it easy to add common things people want. I don't think nodatime is a good library. Using the standard date/time is much easier than the third party library.

    • @IAmTimCorey
      @IAmTimCorey  3 ปีที่แล้ว

      That's not a great take. There is a reason why Noda Time has 41 million downloads. It is a good library. DateTime in C# can be just fine for your needs. That don't negate the need for something more. It just means you aren't bumping up against the problems that other developers are facing. When you do, the additional power of Noda Time is available to help you solve those problems.

    • @andywalter7426
      @andywalter7426 3 ปีที่แล้ว +2

      @@IAmTimCorey If I ran into those problems, it would be much faster for me to create my own functions and use them so I understand perfectly how it works.

    • @IAmTimCorey
      @IAmTimCorey  3 ปีที่แล้ว +2

      I highly doubt you can replicate what Noda Time does in your application "must faster". Don't get caught up in reinventing every wheel because you can "do it better". That's a sure way to never produce deep, quality software. Instead, you have a lot of half-baked "solutions" to all of your problems and no real depth to your actual application. Focus on building your application, not on re-solving every problem you come across.

  • @andywalter7426
    @andywalter7426 3 ปีที่แล้ว +1

    I have one question. How do you add hours, days, etc without creating a new variable. I think they should have a way to add hours, etc, to the existing time and not have to create a new variable. That seems like it would make the system be very slow because you have to create another variable instead of just modifying the existing variable.

    • @tommypuceau
      @tommypuceau 3 ปีที่แล้ว

      Not sure if I got it well, but shouldn't it be myDateTimeVariable = myDateTimeVariable.AddDays(double days) / myDateTimeVariable.AddHours(double hours) ?

    • @fadidib8516
      @fadidib8516 3 ปีที่แล้ว

      @@tommypuceau yes

    • @djProduct2008
      @djProduct2008 3 ปีที่แล้ว

      DateTime is a struct, which are typically immutable for good reason. Take into consideration that you're not actually "newing up" an object that's going to be garbage collected or involve any heavy-weight init code. You do the exact same thing with int, long, float, etc. operations all the time in code without giving it a second thought. int i; integer addition creates a 'new' integer when we call the + operator. Same concept applies to both DateTime & TimeSpan. No need to worry about it, your performance concerns will almost never reside here.

    • @OnlyBESTClub
      @OnlyBESTClub 3 ปีที่แล้ว +1

      @@djProduct2008
      i++ creates a new instance of int?
      I didn't know that.

    • @djProduct2008
      @djProduct2008 3 ปีที่แล้ว +1

      @@OnlyBESTClub So sorry, I should have said an operation like addition, not the increment operator. (updated comment in case anyone else reads that)

  • @andywalter7426
    @andywalter7426 2 ปีที่แล้ว

    The only disappointing part about DateOnly and TimeOnly is you can't store those into the database. If a person uses dapper for database, somehow it works with DateTime but not DateOnly. Really disappointed that they would even introduce a DateOnly but then a person has to find out the hard way that if they are using databases, they will be disappointed by it. This can even block developers from even moving forward to create apps if DateOnly or TimeOnly are requirements.

    • @IAmTimCorey
      @IAmTimCorey  2 ปีที่แล้ว

      These were just released by .NET 6. Now the vendors will need to figure out how to implement them. It isn't as simple as "just allowing it".

    • @andywalter7426
      @andywalter7426 2 ปีที่แล้ว

      @@IAmTimCorey Any suggested workarounds in the meanwhile? because there is so much good use for dateonly and timeonly. Until they get implemented, what is the workaround. Most programmers would be unhappy if they can't do any work until vendors figure out how to handle them.