Python : Datetime - Exercises and Solution


1. Write a Python program to get the first and last second

View Solution

2. Write a Python program to generate RFC 3339 timestamp

View Solution

3. Write a Python program to validate a Gregorian date. The month is between 1 and 12 inclusive, the day is within the allowed number of days for the given month. Leap year’s are taken into consideration. The year is between 1 and 32767 inclusive

View Solution

4. Write a Python program to drop microseconds from datetime

View Solution

5. Write a Python program to get days between two dates

View Solution

6. Write a Python program to get the date of the last Tuesday

View Solution

7. Write a Python program to test the third Monday of a month

View Solution

8. Write a Python program to get the last day of a specified year and month

View Solution

9. Write a Python program to get the number of days of a given month and year

View Solution

10. Write a Python program to add a month with a specified date

View Solution

11. Write a Python program to count the number of Monday of the 1st day of the month from 2014 to 2022

View Solution

12. Write a Python program to print a string ten times, delay two seconds

View Solution

13. Write a Python program calculates the date six months from the current date using the datetime module

View Solution

14. Write a Python program to create 12 fixed dates from a specified date over a given period. The difference between two dates will be 20

View Solution

15. Write a Python program to get the dates 30 days before and after from the current date

View Solution

16. Write a Python program to get the GMT and local current time

View Solution

17. Write a Python program convert a date to timestamp

View Solution

18. Write a Python program convert a string date to the timestamp

View Solution

19. Write a Python program to calculate a number of days between two dates

View Solution

20. Write a Python program to display the date and time in a human-friendly string

View Solution

21. Write a Python program to convert a date to Unix timestamp

View Solution

22. Write a Python program to calculate two date difference in seconds

View Solution

23. Write a Python program to convert two date difference in days, hours, minutes, seconds

View Solution

24. Write a Python program to calculate an age in year

View Solution

25. Write a Python program to get the current date time information

View Solution

26. Write a python program to generate a date and time as a string

View Solution

27. Write a Python program to print a calendar for an entire year

View Solution

28. Write a Python program to print a calendar for month

View Solution

29. Write a Python program to get the current week

View Solution

30. Write a Python program to create a HTML calendar with data for a specific year and month

View Solution

31. Write a Python program display a list of the dates for the 2nd Friday of every month for a given year

View Solution

32. Write a Python program to display a simple, formatted calendar of a given year and month

View Solution

33. Write a Python program to convert a string into datetime

View Solution

34. Write a Python program to get a list of dates between two dates

View Solution

35. Write a Python program to print yesterday, today, tomorrow

View Solution

36. Write a Python program to convert the date to datetime (midnight of the date) in Python

View Solution

37. Write a Python program to print next 5 days starting from today

View Solution

38. Write a Python program to add 5 seconds with the current time

View Solution

39. Write a Python program to convert Year/Month/Day to Day of Year in python

View Solution

40. Write a Python program to get current time in milliseconds in python

View Solution

41. Write a Python program to subtract Three days from current date.

View Solution

42. Write a Python program to get the current time

View Solution

43. Write a Python program to convert a string to datetime

View Solution

44. Write a Python program to determine whether a given year is a leap year

View Solution

45. Write a Python program to select all the Sundays of a specified year

View Solution

46. Write a Python program to Add five days from current date

View Solution

47. Write a Python program to find the date of the first Monday of a given week

View Solution

48. Write a Python program to find the born in the previous millennium or during this millennium given Birthday date

View Solution

49. Write a Python program to Print hour, minute, second, microsecond, day, month, year Given datetim

View Solution

50. Write a Python script to display the various Date Time String formats

  1. Current date and time
  2. Current Date
  3. Current year
  4. Month of year
  5. Week number of the year
  6. Weekday of the week
  7. Day of year
  8. Day of the month
  9. Day of week
  10. Current Time
  11. Current Hour
  12. Current Minute
  13. Current PM / AM
  14. Local Version Date
  15. Local Version Time
View Solution

List of Programs


Sample Programs


Python Database Connection


Python Flask


Python Tkinder Tutorial