Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solución reto #16 Python #1356

Open
grisales54 opened this issue Sep 4, 2024 · 0 comments
Open

Solución reto #16 Python #1356

grisales54 opened this issue Sep 4, 2024 · 0 comments

Comments

@grisales54
Copy link

from datetime import datetime

def dias(fecha1: str, fecha2: str):

fecha_1 = datetime.strptime(
    fecha1, "%d/%m/%Y"
)  # Crea un objeto fecha a partir de un string
fecha_2 = datetime.strptime(fecha2, "%d/%m/%Y")

return print(abs(fecha_2 - fecha_1))  # Resta en valor absoluto de las fechas

dias("1/11/2002", "1/11/2003")

def validar(string: str):

if "/" in string:
    partes = string.split(
        "/"
    )  # divide los datos de caracteres en segmentos en función de los separadores.

    if 0 < int(partes[0]) <= 31:
        if 0 < int(partes[1]) <= 12:
            if 1900 < int(partes[2]) <= 2024:
                return True
            else:
                return False
        else:
            return False
    else:
        return False

r = True

while r:

fecha = input("Ingrese una fecha con el siguiente formato dd/MM/yyyy: ")
fecha2 = input("Ingrese la segunda fecha con el siguiente formato dd/MM/yyyy:")

if validar(fecha) and validar(fecha2):
    dias(fecha, fecha2)
    break

else:
    print("Formato invalido")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant