Python - Imprimir las Fechas

#Ejemplos de Imprimir las fechas en Python:[br][br]#1. Imprimir las fechas de los últimos 10 días:[br]import datetime[br]today = datetime.date.today()[br]for i in range(10):[br] date = today - datetime.timedelta(days=i)[br] print(date)[br][br]#2. Imprimir las fechas de los próximos 10 días:[br]import datetime[br]today = datetime.date.today()[br]for i in range(10):[br] date = today + datetime.timedelta(days=i)[br] print(date)[br][br]#3. Imprimir las fechas de un mes específico:[br]import datetime[br]year = 2023[br]month = 7[br]for day in range(1, 32):[br] try:[br] date = datetime.date(year, month, day)[br] print(date)[br] except ValueError:[br] break[br][br]#4. Imprimir las fechas de un rango de años:[br]import datetime[br]start_year = 2020[br]end_year = 2025[br]for year in range(start_year, end_year + 1):[br] for month in range(1, 13):[br] for day in range(1, 32):[br] try:[br] date = datetime.date(year, month, day)[br] print(date)[br] except ValueError:[br] break[br][br]#5. Imprimir las horas de un día específico:[br]import datetime[br]year = 2023[br]month = 7[br]day = 15[br]for hour in range(24):[br] time = datetime.time(hour)[br] date_time = datetime.datetime(year, month, day, time.hour)[br] print(date_time)[br][br]#6. Imprimir las fechas y horas de un rango de minutos:[br]import datetime[br]start_time = datetime.time(8, 0)[br]end_time = datetime.time(9, 0)[br]for minute in range(0, 60):[br] time = datetime.time(start_time.hour, minute)[br] date_time = datetime.datetime.combine(datetime.date.today(), time)[br] if start_time <= time <= end_time:[br] print(date_time)[br][br]#7. Imprimir las fechas y horas de un rango de segundos:[br]import datetime[br]start_time = datetime.time(8, 0, 0)[br]end_time = datetime.time(8, 0, 10)[br]for second in range(0, 60):[br] time = datetime.time(start_time.hour, start_time.minute, second)[br] date_time = datetime.datetime.combine(datetime.date.today(), time)[br] if start_time <= time <= end_time:[br] print(date_time)[br][br]#8. Imprimir las fechas y horas de un rango de microsegundos:[br]import datetime[br]start_time = datetime.time(8, 0, 0, 0)[br]end_time = datetime.time(8, 0, 0, 100000)[br]for microsecond in range(0, 1000000, 100000):[br] time = datetime.time(start_time.hour, start_time.minute, start_time.second, microsecond)[br] date_time = datetime.datetime.combine(datetime.date.today(), time)[br] if start_time <= time <= end_time:[br] print(date_time)[br][br]#9. Imprimir las fechas y horas de un rango de milisegundos:[br]import datetime[br]start_time = datetime.time(8, 0, 0, 0)[br]end_time = datetime.time(8, 0, 0, 1000)[br]for millisecond in range(0, 1000, 100):[br] time = datetime.time(start_time.hour, start_time.minute, start_time.second, millisecond)[br] date_time = datetime.datetime.combine(datetime.date.today(), time)[br] if start_time <= time <= end_time:[br] print(date_time)[br][br]#10. Imprimir las fechas y horas de un rango de nanosegundos:[br]import datetime[br]start_time = datetime.time(8, 0, 0, 0)[br]end_time = datetime.time(8, 0, 0, 100)[br]for nanosecond in range(0, 1000, 100):[br] time = datetime.time(start_time.hour, start_time.minute, start_time.second, nanosecond)[br] date_time = datetime.datetime.combine(datetime.date.today(), time)[br] if start_time <= time <= end_time:[br] print(date_time)[br] [br]#11. Imprimir las fechas y horas de un rango de años, meses y días:[br]import datetime[br]start_date = datetime.date(2023, 1, 1)[br]end_date = datetime.date(2023, 12, 31)[br]current_date = start_date[br]while current_date <= end_date:[br] print(current_date)[br] current_date += datetime.timedelta(days=1) [br][br]#12. Imprimir las fechas y horas de un rango de horas: [br]import datetime[br]start_datetime = datetime.datetime(2023, 1, 1, 0, 0)[br]end_datetime = datetime.datetime(2023, 1, 1, 23, 59)[br]current_datetime = start_datetime[br]while current_datetime <= end_datetime:[br] print(current_datetime)[br] current_datetime += datetime.timedelta(minutes=30) [br][br]#13. Imprimir las fechas y horas de un rango de años, meses y días: [br]import datetime[br]start_date = datetime.date(2023, 1, 1)[br]end_date = datetime.date(2023, 12, 31)[br]for single_date in range((end_date - start_date).days + 1):[br] current_date = start_date + datetime.timedelta(days=single_date)[br] print(current_date)[br][br]#14. Imprimir las fechas y horas de un rango de horas:[br]import datetime[br]start_datetime = datetime.datetime(2023, 1, 1, 0, 0)[br]end_datetime = datetime.datetime(2023, 1, 1, 23, 59)[br]for single_datetime in range(int((end_datetime - start_datetime).total_seconds() // 1800) + 1):[br] current_datetime = start_datetime + datetime.timedelta(minutes=single_datetime * 30)[br] print(current_datetime)
Geogebra Python

Information: Python - Imprimir las Fechas