from datetime import datetime, time, timedelta

def total_daytime_minutes(start_time, end_time, datetime1, datetime2):
    # Extract date part from datetime objects
    
    date1 = datetime1.date()
    date2 = datetime2.date()

   
    # Define start and end time as time objects
    start_time_obj = time(*start_time)
    end_time_obj = time(*end_time)

    # Create datetime objects with defined times for comparison
    day_start1 = datetime.combine(date1, start_time_obj)
    day_end1 = datetime.combine(date1, end_time_obj)
    day_start2 = datetime.combine(date2, start_time_obj)
    day_end2 = datetime.combine(date2, end_time_obj)

    # Calculate total daytime in minutes
    total_minutes = 0

    if datetime1 <= day_end1 and datetime2 >= day_start1:
        # Calculate overlap duration
        overlap_start = max(datetime1, day_start1)
        overlap_end = min(datetime2, day_end1)
        overlap_duration = (overlap_end - overlap_start).total_seconds() / 60
        total_minutes += max(0, overlap_duration)

    if datetime1 <= day_end2 and datetime2 >= day_start2:
        # Calculate overlap duration
        overlap_start = max(datetime1, day_start2)
        overlap_end = min(datetime2, day_end2)
        overlap_duration = (overlap_end - overlap_start).total_seconds() / 60
        total_minutes += max(0, overlap_duration)

    return total_minutes

