Thamizhiniyan C S
HomeWriteupsResourcesCheatsheets
HackerRank
HackerRank
  • HackerRank
  • Linux Shell
    • Bash
    • Text Processing
      • Cut
      • Head
      • Middle
      • Tail
      • Tr
      • Sort
      • Uniq
      • Paste
    • Arrays In Bash
    • Grep Sed Awk
      • Grep
      • Sed
      • Awk
  • Regex
    • Introduction
    • Character Class
    • Repetitions
    • Grouping and Capturing
    • Backreferences
    • Assertions
    • Applications
  • Python
    • Introduction
    • Basic Data Types
    • Strings
    • Sets
    • Math
    • Itertools
    • Collections
    • Date and Time
    • Errors and Exceptions
    • Classes
    • Built-Ins
    • Python Functionals
    • Regex and Parsing
    • XML
    • Closures and Decorators
    • Numpy
    • Debugging
  • C
    • Introduction
    • Conditionals and Loops
    • Arrays and Strings
Powered by GitBook
On this page
  • Calender Module
  • Time Delta

Was this helpful?

  1. Python

Date and Time

PreviousCollectionsNextErrors and Exceptions

Last updated 1 year ago

Was this helpful?

Calender Module

from calendar import weekday, day_name

month, date, year = map(int, input().split())

print(day_name[weekday(year, month, date)].upper())

Time Delta

from datetime import datetime


def time_delta(t1, t2):
    time_format = '%a %d %b %Y %H:%M:%S %z'
    time1 = datetime.strptime(t1, time_format)
    time2 = datetime.strptime(t2, time_format)
    print(int((abs(time1 - time2)).total_seconds()))


if __name__ == '__main__':
    for _ in range(int(input())):
        time_delta(input(), input())
Solve Programming Questions | HackerRankHackerRank
Logo