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

  Рет қаралды 17,090

IAmTimCorey

IAmTimCorey

Күн бұрын

The DateTime keyword in C# is commonly used, but have you ever really explored all that it can do? In this video, we are going to look at the DateTime object and what it represents, identify how to use it to get relevant data out, manipulate it, display it in the various formats, and a lot more.
We will also be looking at how the DateOnly and TimeOnly types in .NET 6 will help supplement what DateTime can do.
Full Training Courses: IAmTimCorey.com
Source Code: leadmagnets.ap...
Mailing List: signup.iamtimc...

Пікірлер: 67
@mrsajjad30
@mrsajjad30 2 жыл бұрын
This is it. My search for date-time tutorials ends here. Thank you Mr. Corey.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@williamFrSFO16
@williamFrSFO16 2 жыл бұрын
Me too!
@torgeirullestad3921
@torgeirullestad3921 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 2 жыл бұрын
Hopefully it will help someone else who was in your shoes five years ago.
@torrvic1156
@torrvic1156 8 ай бұрын
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 8 ай бұрын
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/
@BogLungu
@BogLungu 2 жыл бұрын
Tim ! Fantastic topic ! Please keep in mind! A video like this for “multi trading “ will be incredibly!
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
I will add it to the list. Thanks for the suggestion.
@digitallight8113
@digitallight8113 Жыл бұрын
Thanks Tim! Awesome video about Datetime
@IAmTimCorey
@IAmTimCorey 11 ай бұрын
You are welcome.
@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.
@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.
@d3tn3tracer
@d3tn3tracer 2 жыл бұрын
Thank you for nice course Mr. Corey! :) Now I can be DateTime master. Nice explained it for me.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@attilaguba856
@attilaguba856 2 жыл бұрын
Exactly that's what I've been searching for long time! Thank You !
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@attilaguba856
@attilaguba856 2 жыл бұрын
@@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 😊
@yerkebulanserikbayev4736
@yerkebulanserikbayev4736 2 жыл бұрын
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?
@getimad1076
@getimad1076 2 жыл бұрын
Man I really enjoyed this tutorial. Thank You ❤
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@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.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Thank you!
@latinofac1981
@latinofac1981 2 жыл бұрын
As usual.. great content! Thank you for sharing!
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@amirmehdihosseini
@amirmehdihosseini 2 ай бұрын
nice job. helpful.
@IAmTimCorey
@IAmTimCorey 2 ай бұрын
I am glad it was helpful.
@everabyss
@everabyss Жыл бұрын
Good job!
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Thanks!
@BogLungu
@BogLungu 2 жыл бұрын
This is fantastic! Thank you!
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@LifeWithSeb99
@LifeWithSeb99 2 жыл бұрын
Are we gonna get black Friday discounts on your courses, Tim? 😆
@attilaguba856
@attilaguba856 2 жыл бұрын
Hope so 😁
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
There usually are.
@scwyldspirit
@scwyldspirit 2 жыл бұрын
Hey Tim are you planning on going over the dependency injection in Dotnet 6?
@alekseev74
@alekseev74 2 жыл бұрын
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.
@uppercat7268
@uppercat7268 2 жыл бұрын
tim the time traveler teaches timespan things :)
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Thanks! 😉
@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 жыл бұрын
Not in that specific instance.
@michaelschneider603
@michaelschneider603 2 жыл бұрын
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? :-)
@gdenzilg
@gdenzilg 2 жыл бұрын
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 8 ай бұрын
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.
@maciekJazzy
@maciekJazzy 2 жыл бұрын
Thanks man!!!
@tomthelestaff-iamtimcorey7597
@tomthelestaff-iamtimcorey7597 2 жыл бұрын
Thanks for watching!
@davidwhite2011
@davidwhite2011 2 жыл бұрын
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 2 жыл бұрын
You could do date.AddMonths(1) until date is equal to January 8th 2021
@azgan123
@azgan123 2 жыл бұрын
Can you make a course about how to use c/cpp API in c#? I'll pay!
@andywalter7426
@andywalter7426 2 жыл бұрын
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 2 жыл бұрын
Not sure if I got it well, but shouldn't it be myDateTimeVariable = myDateTimeVariable.AddDays(double days) / myDateTimeVariable.AddHours(double hours) ?
@fadidib8516
@fadidib8516 2 жыл бұрын
@@tommypuceau yes
@djProduct2008
@djProduct2008 2 жыл бұрын
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 2 жыл бұрын
@@djProduct2008 i++ creates a new instance of int? I didn't know that.
@djProduct2008
@djProduct2008 2 жыл бұрын
@@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 жыл бұрын
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 2 жыл бұрын
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 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 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 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.
Intro to Records in C# 9 - How To Use Records And When To Use Them
1:19:44
.NET and C# are in trouble. Here is what I'd do.
10:57
Ed Andersen
Рет қаралды 64 М.
GIANT Gummy Worm Pt.6 #shorts
00:46
Mr DegrEE
Рет қаралды 10 МЛН
Как подписать? 😂 #shorts
00:10
Денис Кукояка
Рет қаралды 5 МЛН
C# Namespace & Using Deep Dive - Including .NET 6 Changes
43:30
IAmTimCorey
Рет қаралды 26 М.
Working with Null in .NET 6 and C# 10
57:26
IAmTimCorey
Рет қаралды 36 М.
The Problem with Time That .NET 8 Finally Fixed
9:47
Nick Chapsas
Рет қаралды 75 М.
No, Einstein Didn’t Solve the Biggest Problem in Physics
8:04
Sabine Hossenfelder
Рет қаралды 205 М.
40 Years Of Software Engineering Experience In 19 Minutes
19:10
Continuous Delivery
Рет қаралды 62 М.
Introduction to DateTime in C#: Master the Basics!
23:39
Nick Proud
Рет қаралды 1,6 М.
The RIGHT way to deal with Date and Time in C#
8:31
Nick Chapsas
Рет қаралды 64 М.
Inheritance vs Interfaces in C#: Object Oriented Programming
49:41
IAmTimCorey
Рет қаралды 102 М.
GIANT Gummy Worm Pt.6 #shorts
00:46
Mr DegrEE
Рет қаралды 10 МЛН