fecha contiene funciones para manipular y formatear la fecha y hora del sistema. DateTime fecha= new DateTime (int year, int month, int day); DateTime fechaConHora = new DateTime (int year, int month, int day, int hour, int minute, int sec); Cambiar la estructura de como te lo enseña: Console.WriteLine(fecha. ToString()); Console.WriteLine(fecha.ToString("MM/dd/yyyy")); Estructura Para que te de el dia en especifico o con la hora: Console.WriteLine(fechaConHora.DayOfWeek); Console.WriteLine(fechaConHora.Date);
Saber cuanto días faltan para el día elegido
Console.WriteLine(fecha.Subtract(fechaConHora).Days); Para qué sirve Se usa más comúnmente para bancos, cuando los bancos quieren saber cuándo va a ser el último día que cada persona tiene que pagar o cuanto falta para que eso suceda using System; Estructura class Program { static void Main() DateTime newDate = dateTime.AddDays(5); { Console.WriteLine($"Date after adding 5 days: {newDate}"); Console.WriteLine("Enter a date (yyyy-mm-dd):"); string dateInput = Console.ReadLine(); string customFormat = dateTime.ToString("dddd, MMMM dd, yyyy 'at' h:mm tt"); Console.WriteLine("Enter a time (hh:mm:ss):"); Console.WriteLine($"Custom formatted date: string timeInput = Console.ReadLine(); {customFormat}"); } if (DateTime.TryParse($"{dateInput} {timeInput}", out else DateTime dateTime)) { { Console.WriteLine($"You entered: {dateTime}"); Console.WriteLine("Invalid date or time format."); Console.WriteLine($"Day of week: } {dateTime.DayOfWeek}"); } Console.WriteLine($"Is it a leap year? {DateTime.IsLeapYear(dateTime.Year)}");