Sort by

recency

|

380 Discussions

|

  • + 0 comments
    1. from datetime import datetime
    2. def time_delta(t1, t2):
    3. dt_stamp = "%a %d %b %Y %H:%M:%S %z"
    4. game = datetime.strptime(t1,dt_stamp)- datetime.strptime(t2,dt_stamp)
    5. exact_sec = abs(int((game).total_seconds()))
    6. print(exact_sec)
  • + 0 comments
    #!/bin/python3
    
    import os
    from datetime import datetime
    
    # Complete the time_delta function below.
    def time_delta(t1, t2):
        # Define the date format
        date_format = "%a %d %b %Y %H:%M:%S %z"
        
        # Parse the input strings into datetime objects
        dt1 = datetime.strptime(t1, date_format)
        dt2 = datetime.strptime(t2, date_format)
        
        # Calculate the absolute difference in seconds
        delta = abs((dt1 - dt2).total_seconds())
        
        # Return the result as a string
        return str(int(delta))
    
    if __name__ == '__main__':
        fptr = open(os.environ['OUTPUT_PATH'], 'w')
        
        t = int(input())
        
        for t_itr in range(t):
            t1 = input()
            t2 = input()
            
            delta = time_delta(t1, t2)
            
            fptr.write(delta + '\n')
        
        fptr.close()
    
  • + 0 comments

    date_format = "%a %d %b %Y %H:%M:%S %z"

    d1 = datetime.strptime(t1, date_format)
    d2 = datetime.strptime(t2, date_format)
    
    x=abs(d1-d2)
    print(x)
    print (str(int((x.total_seconds()))))
    

    why is the above giving me error?

    why

  • + 0 comments

    my code!!

    from datetime import datetime

    def time_delta(t1, t2): format_str = "%a %d %b %Y %H:%M:%S %z" datetime1 = datetime.strptime(t1, format_str) datetime2 = datetime.strptime(t2, format_str) delta = abs((datetime1 - datetime2).total_seconds()) return str(int(delta))

    if name == "main": t = int(input()) for _ in range(t): t1 = input().strip() t2 = input().strip() print(time_delta(t1, t2))

  • + 0 comments

    It's a great exercise to reinforce working with date-time formats and conversions. Calculating the absolute difference in seconds requires careful handling of the time zone offsets. Mahadev bet777