How to store datetime with millisecond precision in SQL database

alphanumeric

With a float value representing date and time with millisecond precision:

import datetime
float_time = 1485538757.29289
print datetime.datetime.fromtimestamp(float_time) 

prints:

2017-01-27 09:39:17.292890

To store it in db:

from sqlalchemy import Column, DateTime
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class MyTable(Base):
    __tablename__ = 'mytable'
    time_created = Column(DateTime, nullable=False)

But saved value is rounded down to 2017-01-27 09:39:17 (from 2017-01-27 09:39:17.292890). Is there is a solution?

meshy

It depends on the SQL database you're using. They differ in precision:

PostgresQL: Default 1 microsecond. (See docs for far-future/past caveats.)

MySQL: Default 1 second. Millisecond / microsecond precision optional after version 5.6.4.

MariaDB: Default 1 second. Millisecond / microsecond precision optional since version 5.3.

Transact-SQL (Microsoft SQL): Rounded to increments of .000, .003, or .007 seconds

SQLite: Datetimes can be stored as strings with arbitrary precision, but "only the first three digits are significant".

Oracle: Default 1 microsecond. Optional precision to 1 nanosecond.

Note:

  • Millisecond: 0.001s
  • Microsecond: 0.000001s
  • Nanosecond: 0.000000001s

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to ntp server time down to millisecond precision using Python ntplib?

分類Dev

Remove millisecond part of created_at in SQL to compare with other datetime

分類Dev

How to sum a Time column (with millisecond) in SQL Server

分類Dev

Is there a way of getting 'now' (at least) to millisecond precision in Julia?

分類Dev

Rounding of the millisecond part in Linux datetime

分類Dev

How to store Excel sheet data in SQL Server database

分類Dev

Insert and update a datetime into SQL database

分類Dev

read in string as datetime object with 3 digits for millisecond

分類Dev

How to store a PropertyBag class into database

分類Dev

How to create a geography and double precision database columns in Rails

分類Dev

SQL store the join result into a new database table

分類Dev

How to store DateTime at UTC format with Java 8?

分類Dev

How to store Google classroom Assignment and assessments data in our SQL database using Google classroom API

分類Dev

How to compare sql datetime and c# datetime

分類Dev

Docker Compose - How to store database data?

分類Dev

How to design database in order to store "default" items

分類Dev

How to store database records into hash ruby on rails

分類Dev

How to count records in sql database?

分類Dev

How to convert varchar date into datetime in sql

分類Dev

How to store sql column name in form value

分類Dev

How to increase precision in matplotlib?

分類Dev

sql query to average, after grouping by date part of millisecond

分類Dev

SQL Server Numeric with different precision

分類Dev

How to store emoji string in Database using Laravel with Orm Query

分類Dev

How to use a database with a messenger chat bot to store responses of users?

分類Dev

How do i store an ArrayList of users in a Firebase Database in Android?

分類Dev

How to Store RichTextBox Content to SQLServer Database in WPF using Entity Framework

分類Dev

How to convert String to Date which can be store in database?

分類Dev

How to change the file name before store in file and database

Related 関連記事

  1. 1

    How to ntp server time down to millisecond precision using Python ntplib?

  2. 2

    Remove millisecond part of created_at in SQL to compare with other datetime

  3. 3

    How to sum a Time column (with millisecond) in SQL Server

  4. 4

    Is there a way of getting 'now' (at least) to millisecond precision in Julia?

  5. 5

    Rounding of the millisecond part in Linux datetime

  6. 6

    How to store Excel sheet data in SQL Server database

  7. 7

    Insert and update a datetime into SQL database

  8. 8

    read in string as datetime object with 3 digits for millisecond

  9. 9

    How to store a PropertyBag class into database

  10. 10

    How to create a geography and double precision database columns in Rails

  11. 11

    SQL store the join result into a new database table

  12. 12

    How to store DateTime at UTC format with Java 8?

  13. 13

    How to store Google classroom Assignment and assessments data in our SQL database using Google classroom API

  14. 14

    How to compare sql datetime and c# datetime

  15. 15

    Docker Compose - How to store database data?

  16. 16

    How to design database in order to store "default" items

  17. 17

    How to store database records into hash ruby on rails

  18. 18

    How to count records in sql database?

  19. 19

    How to convert varchar date into datetime in sql

  20. 20

    How to store sql column name in form value

  21. 21

    How to increase precision in matplotlib?

  22. 22

    sql query to average, after grouping by date part of millisecond

  23. 23

    SQL Server Numeric with different precision

  24. 24

    How to store emoji string in Database using Laravel with Orm Query

  25. 25

    How to use a database with a messenger chat bot to store responses of users?

  26. 26

    How do i store an ArrayList of users in a Firebase Database in Android?

  27. 27

    How to Store RichTextBox Content to SQLServer Database in WPF using Entity Framework

  28. 28

    How to convert String to Date which can be store in database?

  29. 29

    How to change the file name before store in file and database

ホットタグ

アーカイブ