question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fractional DateTimeField values

See original GitHub issue

The fractional part of a datetime object seems to be always truncated. Looking through the code a bit, I also see that it doesn’t expect there to be one: https://github.com/coleifer/peewee/blob/master/peewee.py#L204

I assume this is primarily cause not all databases support fractional seconds (older versions of MySQL, for instance). Is there a way to optionally support it if the database underneath supports it?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

6reactions
binderclipcommented, Apr 28, 2016

After read the information you provided, I got this, and it seems work:

database = MySQLDatabase(dbname, fields={'datetime_fsp6': 'DATETIME(6)'})
class DateTimeFsp6Field(DateTimeField):
    db_field = 'datetime_fsp6'
class FooModel(Model):
    ctime = DateTimeFsp6Field(default=datetime.datetime.now)
0reactions
mindojo-victorcommented, Nov 30, 2017

@luisulloa IIUC, not all MySql versions support this

Read more comments on GitHub >

github_iconTop Results From Across the Web

11.2.6 Fractional Seconds in Time Values
MySQL has fractional seconds support for TIME , DATETIME , and TIMESTAMP values, with up to microseconds (6 digits) precision:.
Read more >
Datetime values - IBM
A timestamp is a six or seven-part value (year, month, day, hour, minute, second, and optional fractions of a second) designating a date...
Read more >
Django datetime field fractional support - Stack Overflow
I was using the MySQL 5.5 without fractional support but there are records in my database that have the same datetime field and...
Read more >
How to Return Fractional Seconds from a Datetime Value in ...
To return the fractional seconds part from a datetime value, use the FF format element. Example. Here's an example to demonstrate: SELECT ...
Read more >
Why are fractional seconds in date/time values truncated in ...
do not support fractional seconds. While. "myDateField DATETIME(6)". does supports fractional seconds up to micro seconds. See: https://dev.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found