Hi @Laura Edith Hernández Hilario , Welcome to Microsoft Q&A.
You can use string.Format
to format your datetime perfectly.
Choose the format you need:Such as year (yyyy or yy), month (MM or MMM), date (dd), hour (HH or hh), minute (mm) and so on.
DateTime now = DateTime.Now;
string formattedDate = string.Format("{0:dd/MM/yyyy}", now);
Console.WriteLine(formattedDate); // Output: 01/06/2023
string formattedTime = string.Format("{0:HH:mm}", now);
Console.WriteLine(formattedTime); // Output::09:30
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.