By deveton

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.


@iSR5 2019-12-03 01:13:32

programmatically speaking, you can do both. the only difference between them (in code) is this :

 // using 00:00:00 will require you to add 1 day to the end date in order to count as full day
 if(time >= "2019-12-03 00:00:00" && time <= "2019-12-04 00:00:00")

//using 23:59:59 will not require you to add 1 day to the end date.
 if(time >= "2019-12-03 00:00:00" && time <= "2019-12-03 23:59:59")

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:

var xx = DateTime.MaxValue.ToString("HH:mm:ss.fffffff");
var xy = DateTime.MinValue.ToString("HH:mm:ss.fffffff");




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 that DateTime can represent; that is to say, the 'last' point in a day. Conversely, the .Date property makes use of 00: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.

Related Questions

Sponsored Content

36 Answered Questions

[SOLVED] How to get the current time in Python

  • 2009-01-06 04:54:23
  • user46646
  • 3093570 View
  • 2644 Score
  • 36 Answer
  • Tags:   python datetime time

37 Answered Questions

[SOLVED] How do I get the current date and time in PHP?

  • 2009-01-22 20:09:18
  • Mike
  • 2199767 View
  • 810 Score
  • 37 Answer
  • Tags:   php datetime

18 Answered Questions

10 Answered Questions

[SOLVED] How to escape braces (curly brackets) in a format string in .NET

37 Answered Questions

[SOLVED] Should I use the datetime or timestamp data type in MySQL?

11 Answered Questions

[SOLVED] Should 'using' directives be inside or outside the namespace?

37 Answered Questions

[SOLVED] Calculate relative time in C#

15 Answered Questions

[SOLVED] C# DateTime to "YYYYMMDDHHMMSS" format

  • 2010-06-11 18:43:49
  • 1348287 View
  • 594 Score
  • 15 Answer
  • Tags:   c# datetime

Sponsored Content