2019-12-02 22:38:00 8 Comments
When I search about maximum time. people always answering that from VS debugger. which is 23:59:59.9999999
As I need 12 AM in 24 formats. I guess it will be 00:00:00 but... C# .NET assume the following:
var xx = DateTime.MaxValue.ToString("HH:mm:ss.fffffff");
When debugging previous it will print 23:59:59.9999999
What should I use? does it matter? what's the difference?
Should use 00:00:00 ? or 23:59:59.9999999 Specially when saving Time in SQL-Server.
The big problem or I mean un-good behavior for end-user when you convert 24 formats to 12 Hour format via hh:mm:ss it will show 11:59:59 PM
it will be ugly isn't it? it should be 12:00:00 AM.
After All, Obsidian Age answered this well depending on the use case.
Related Questions
Sponsored Content
36 Answered Questions
37 Answered Questions
18 Answered Questions
[SOLVED] Given a DateTime object, how do I get an ISO 8601 date in string format?
- 2008-09-22 13:56:08
- Iain
- 474220 View
- 741 Score
- 18 Answer
- Tags: c# datetime datetime-format iso8601
10 Answered Questions
[SOLVED] How to escape braces (curly brackets) in a format string in .NET
- 2008-09-18 10:04:48
- Pop Catalin
- 270560 View
- 958 Score
- 10 Answer
- Tags: c# .net string parsing formatting
37 Answered Questions
[SOLVED] Should I use the datetime or timestamp data type in MySQL?
- 2009-01-03 16:14:37
- karlipoppins
- 842694 View
- 2605 Score
- 37 Answer
- Tags: mysql datetime timestamp sqldatatypes
11 Answered Questions
[SOLVED] Should 'using' directives be inside or outside the namespace?
- 2008-09-24 03:49:50
- benPearce
- 194646 View
- 1981 Score
- 11 Answer
- Tags: c# .net namespaces stylecop code-organization
37 Answered Questions
[SOLVED] Calculate relative time in C#
- 2008-07-31 23:55:37
- Jeff Atwood
- 153201 View
- 1465 Score
- 37 Answer
- Tags: c# datetime time datediff relative-time-span
3 comments
@iSR5 2019-12-03 01:13:32
programmatically speaking, you can do both. the only difference between them (in code) is this :
so, basically, if you use
23:59:59
there is a one second off the grid, if any record has been stored in this second, it'll not be included in the results. while the second one will include it.Which one to use ? surely the
00:00:00
if you want to be more precise, however, I've not seen any difference in the results in my projects as I've used both of them in different projects. But I'm sure there are some projects needs to include every micro second as this microsecond could change the result's curve (such as analytics or deep learning ..etc).In SQL Server, don't save the time as string, save it with the correct datatype (DateTime, TimeSpan ..etc). SQL Server will reads the time perfectly fine when you pass a correspond time datatype from your application.
@deveton 2019-12-03 11:03:14
but IDK why you do string comparison with timespan? can you give real-example in c#
@Peter Smith 2019-12-02 22:45:01
It depends on perspective:
Gives
So, one is the end of the day and the other is the beginning of the day.
There's an interesting novel called 'The time between midnight'
@Obsidian Age 2019-12-02 22:46:08
DateTime.MaxValue
is exactly that - the maximum value thatDateTime
can represent; that is to say, the 'last' point in a day. Conversely, the.Date
property makes use of00:00:00
by default, as it has no notion of time (unless specified).If you have an event that occurs at exactly midnight, I would recommend storing it as
00:00:00
, as the event occurs at midnight, and you want to accurately represent that.Ultimately, it really depends on your desired use case as to which one you want to use. Do you want to state that the event occurs on day 1's evening, or day 2's beginning? That is what it boils down to, although in the vast majority of cases such a delineation makes no difference. In this case you would want to opt for both the accuracy and 'ease' of
00:00:00
.