About DateTime
1. What is the DateTime Type?
When dealing with dates, the DateTime type is used. The DateTime type allows you to retrieve and specify dates and times.
2. Operations with DateTime Type
Here are some common operations performed with the DateTime type:
Retrieve the current date and time:
Variables name.Now.ToString → 2020/04/01 12:00:00
Retrieve only the current date:
Variable name.Now.ToString("yyyy/MM/dd") → 2020/04/01
Retrieve the date of the next day:
Variable name.Now.Adddays(1).ToString("yyyy/MM/dd") → 2020/04/02
Retrieve the date of the previous day:
Variable name.Now.Adddays(-1).ToString("yyyy/MM/dd") → 2020/03/31
Retrieve the date of the next month:
Variable name.Now.AddMonths(1).ToString("yyyy/MM/dd") → 2020/05/01
Retrieve the date of the next year:
Variable name.Now.Addyears(1).ToString("yyyy/MM/dd") → 2021/04/01
Retrieve the current day of the week:
Variable name.Now.ToString("ddd") → Wednesday
Note: The initial value for DateTime type is "0001/01/01 0:00:00".
3. Date Formats
Here are the formats used to specify dates:
By using these formats, you can customize how dates and times are displayed and manipulated in your application. If you have any questions or need further examples, feel free to ask!
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article