How do I display the current day in a program? But I did not want to take the zero to the left. For example: on 01 I want it to be 1, on 02 I want it to be 2.
How do I display the current day in a program? But I did not want to take the zero to the left. For example: on 01 I want it to be 1, on 02 I want it to be 2.
The basis for what you need is DateTime.Today
(or DateTime.Now
, the difference between them is that Now
contains the time).
This returns the current date, on an object of type DateTime
, to convert to string
with specific formatting, you can use the ToString
method.
The formatting you want is d/M/yyyy
DateTime.Today.ToString("d/M/yyyy");
If you want to return only the day, in string you have to use the format "d "
(note the space after the "d"), because d itself represents a default format.
However, keep in mind that the DateTime
structure contains members like Day
, Month
, Year
, among others. Chances are you might need one of these.