About DateTime

Created by akaBot Support, Modified on Tue, 6 Aug, 2024 at 2:56 PM by akaBot Support

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:

Format
Description
Example
yyyy
4-digit year
2020
MM
2-digit month
04
dd
2-digit day
01
hh
2-digit hour
00
mm
2-digit minute
00
ss
2-digit second
00
ddd
Day of the week
Wednesday

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

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article