0
How do I display the current day in a program? But I didn’t want to take the zero left. For example: the day 01 I want to be 1, the day 02 I want to be 2.
0
How do I display the current day in a program? But I didn’t want to take the zero left. For example: the day 01 I want to be 1, the day 02 I want to be 2.
5
The basis for what you need is the DateTime.Today (or DateTime.Now, the difference between them is that the Now contains the time).
This returns the current date, in an object of the type DateTime, to convert to string with specific formatting, you can use the method ToString.
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 will have to use the format "d " (note the space after "d"), because d itself represents a standard format.
However, keep in mind that the structure DateTime contains members as Day, Month, Year, among others. You probably need one of these.
Browser other questions tagged c#
You are not signed in. Login or sign up in order to post.
That way today for example would be 3/10/2018? If I want to catch only the day, I can put the "d" inside the Tostring?
– Guilherme Wayne
@Guilhermewayne I made an edition in reply.
– Jéf Bueno
@Guilhermewayne You can also use Datetime.Now (https://www.dotnetperls.com/datetime-now)
– PauloHDSousa
Thank you very much LINQ helped a lot. Paulohdsouza helped me a lot tbm with this site
– Guilherme Wayne