Locked lesson.
About this lesson
Let's explore the various functions we can use to display and use the DateTime data type.
Exercise files
Download this lesson’s related exercise files.
8 - DateTime Functions.docx60.9 KB 8 - DateTime Functions SOLUTION.docx
57.9 KB
Quick reference
DateTime Functions
DateTime Functions allow us to do things with our DateTime instances.
When to use
Use these as needed.
Instructions
DateTime myDate = DateTime.Now;
myDate.ToShortDateString(); // Just returns the Date
myDate.ToShortTimeString(); // Just returns the Time
myDate.ToLongDateString(); // Returns Long Date With Words
myDate.ToLongTimeString(); // Returns Time With Seconds
myDate.AddDays(10); // Add 10 Days
myDate.AddDays(-10); // Subtract 10 Days
myDate.AddYears(20); // Add 20 years
Hints & tips
- Use the DateTime Functions to manipulate your dates and times as needed
Lesson notes are only available for subscribers.