Sort by

recency

|

388 Discussions

|

  • + 0 comments

    Here is HackerRank Time Delta in python solution - https://programmingoneonone.com/hackerrank-time-delta-problem-solution-in-python.html

  • + 0 comments

    #!/bin/python3 from datetime import datetime import math import os import random import re import sys

    Complete the time_delta function below.

    def time_delta(t1, t2):

    fmt = '%a %d %b %Y %H:%M:%S %z'
    
    
    dt1 = datetime.strptime(t1,fmt)
    
    dt2 = datetime.strptime(t2,fmt)
    
    return str(int(abs((dt1-dt2).total_seconds())))
    

    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
    def time_delta(t1, t2):
        fmt = "%a %d %b %Y %H:%M:%S %z"
        d1 = datetime.strptime(t1, fmt)
        d2 = datetime.strptime(t2, fmt)
        diff = (d1 - d2).total_seconds() 
        return str(int(abs(diff)))
    
  • + 0 comments
    format = '%a %d %b %Y %H:%M:%S %z'
        t1_str = datetime.datetime.strptime(t1, format)
        t2_str = datetime.datetime.strptime(t2, format)
        diff = t1_str - t2_str
        seconds = abs(int(diff.total_seconds()))
        
        return str(seconds)
    
  • + 0 comments

    t1 = datetime.strptime(t1, "%a %d %b %Y %H:%M:%S %z") t2 = datetime.strptime(t2, "%a %d %b %Y %H:%M:%S %z")

    if(t1>t2):
        x = abs((t1 - t2).seconds)
        y = abs((t1 - t2).days)
    else:
        x = abs((t2 - t1).seconds)
        y = abs((t2 - t1).days)
    
    return str(y*3600*24 + x)