[Python] Create datetime object, accounting for possible next day

Discussão em 'Python' iniciado por Stack, Maio 17, 2025.

  1. Stack

    Stack Membro Participativo

    I am processing data from a form. I have imported the data as a dataframe.

    The form has an initial date and time that have been converted into a datetime object. Partway through the form is a second time that is stored as a time object.

    I wish to create a datetime object for the second time. However, the date may be the next day.

    For instance, if the initial date was 1/1/2025 and the time was 10:25 PM, and the next time was 01:25 AM I wish to create a datetime for 2/1/2025 at 1:25 AM. (using British date convention d/m/y in the example).

    Is there a straightforward way to do this within a dataframe?

    Example (not in a dataframe):

    initialDate = date(2025,1,1)
    initialTime = time(22,25)
    initialDatetime = datetime(2025, 1, 1, 22, 25)
    secondTime = time(1, 25)

    Continue reading...

Compartilhe esta Página