MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / DateTime

Class DateTime

lib/sqlalchemy/sql/sqltypes.py:818–882  ·  view source on GitHub ↗

A type for ``datetime.datetime()`` objects. Date and time types return objects from the Python ``datetime`` module. Most DBAPIs have built in support for the datetime module, with the noted exception of SQLite. In the case of SQLite, date and time types are stored as strings which

Source from the content-addressed store, hash-verified

816
817
818class DateTime(
819 _RenderISO8601NoT, HasExpressionLookup, TypeEngine[dt.datetime]
820):
821 """A type for ``datetime.datetime()`` objects.
822
823 Date and time types return objects from the Python ``datetime``
824 module. Most DBAPIs have built in support for the datetime
825 module, with the noted exception of SQLite. In the case of
826 SQLite, date and time types are stored as strings which are then
827 converted back to datetime objects when rows are returned.
828
829 For the time representation within the datetime type, some
830 backends include additional options, such as timezone support and
831 fractional seconds support. For fractional seconds, use the
832 dialect-specific datatype, such as :class:`.mysql.TIME`. For
833 timezone support, use at least the :class:`_types.TIMESTAMP` datatype,
834 if not the dialect-specific datatype object.
835
836 """
837
838 __visit_name__ = "datetime"
839
840 operator_classes = OperatorClass.DATETIME
841
842 def __init__(self, timezone: bool = False):
843 """Construct a new :class:`.DateTime`.
844
845 :param timezone: boolean. Indicates that the datetime type should
846 enable timezone support, if available on the
847 **base date/time-holding type only**. It is recommended
848 to make use of the :class:`_types.TIMESTAMP` datatype directly when
849 using this flag, as some databases include separate generic
850 date/time-holding types distinct from the timezone-capable
851 TIMESTAMP datatype, such as Oracle Database.
852
853
854 """
855 self.timezone = timezone
856
857 def get_dbapi_type(self, dbapi):
858 return dbapi.DATETIME
859
860 def _resolve_for_literal(self, value):
861 with_timezone = value.tzinfo is not None
862 if with_timezone and not self.timezone:
863 return DATETIME_TIMEZONE
864 else:
865 return self
866
867 def literal_processor(self, dialect):
868 return self._literal_processor_datetime(dialect)
869
870 @property
871 def python_type(self):
872 return dt.datetime
873
874 @util.memoized_property
875 def _expression_adaptations(self):

Callers 12

goMethod · 0.90
CoreFixturesClass · 0.90
core_ddl.pyFile · 0.90
define_tablesMethod · 0.90
test_date_reflectionMethod · 0.90
define_tablesMethod · 0.90
date_fixtureMethod · 0.90
test_time_typesMethod · 0.90
sqltypes.pyFile · 0.85
DateTimeTZTestClass · 0.85

Calls

no outgoing calls

Tested by 8

goMethod · 0.72
define_tablesMethod · 0.72
test_date_reflectionMethod · 0.72
define_tablesMethod · 0.72
date_fixtureMethod · 0.72
test_time_typesMethod · 0.72