C# || How To Get The Date Value & Time Value From A Date Using C#

The following is a module with functions which demonstrates how to get the date value and time value from a DateTime using C#.

The functions listed on this page demonstrates how to isolate the date portion of a date, as well as the time portion of a date. For example, given the date “5/23/2019 7:28:31 PM”, the date value would be 5/23/2019, and time value 7:28:31 PM.


1. Date Value

The example below demonstrates the use of ‘Utils.Methods.DateValue‘ to get the date value of a date.

The DateTime object value contains the date information, with the time portion set to midnight (00:00:00)


2. Time Value

The example below demonstrates the use of ‘Utils.Methods.TimeValue‘ to get the date value of a date.

The DateTime object contains the time information, with the date portion set to January 1 of the year 1


3. Utils Namespace

The following is the Utils Namespace. Include this in your project to start using!


4. More Examples

Below are more examples demonstrating the use of the ‘Utils‘ Namespace. Don’t forget to include the module when running the examples!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

Was this article helpful?
👍 YesNo

Leave a Reply