times (module)

Some time functions to be used with logging etc

Author

David Young

Classes

str([object])

str(bytes_or_buffer[, encoding[, errors]]) -> str

Functions

calculate_time_difference(startDate, endDate)

Return the time difference between two dates as a string

datetime_relative_to_now(date)

*convert date to a relative datetime (e.g.

get_now_sql_datetime()

A datetime stamp in MySQL format: ‘YYYY-MM-DDTHH:MM:SS’

Sub-modules

calculate_time_difference(startDate, endDate)

Return the time difference between two dates as a string

datetime_relative_to_now(date)

*convert date to a relative datetime (e.g.

get_now_sql_datetime()

A datetime stamp in MySQL format: ‘YYYY-MM-DDTHH:MM:SS’

os

OS routines for NT or Posix depending on what system we’re on.

str([object])

str(bytes_or_buffer[, encoding[, errors]]) -> str

sys

This module provides access to some objects used or maintained by the interpreter and to functions that interact strongly with the interpreter.

calculate_time_difference(startDate, endDate)[source]

Return the time difference between two dates as a string

Key Arguments

  • startDate – the first date in YYYY-MM-DDTHH:MM:SS format

  • endDate – the final date YYYY-MM-DDTHH:MM:SS format

Return

  • relTime – the difference between the two dates in Y,M,D,h,m,s (string)

Usage

from fundamentals import times
diff = times.calculate_time_difference(startDate="2015-10-13 10:02:12", endDate="2017-11-04 16:47:05")
print diff

# OUT: 2yrs 22dys 6h 44m 53s
datetime_relative_to_now(date)[source]

convert date to a relative datetime (e.g. +15m, +2hr, +1w)

Key Arguments

  • date – absolute date

Return

  • a relative date

Usage

from fundamentals import times
relTime = times.datetime_relative_to_now(date)
get_now_sql_datetime()[source]

A datetime stamp in MySQL format: ‘YYYY-MM-DDTHH:MM:SS’

Return

  • now – current time and date in MySQL format

Usage

from fundamentals import times
now = times.get_now_sql_datetime()
print now

# OUT: 2016-03-18T11:08:23