Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7005631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:22:32+00:00 2026-05-27T21:22:32+00:00

I need a universal way to store dates and datetimes in several databases (for

  • 0

I need a universal way to store dates and datetimes in several databases (for now Sqlite, MySql and PostgreSql).
I need datetimes to have microseconds precision.

  • Sqlite does not have date and datimes built in.
  • MySql datetime does not have microseconds precision.

So i thought to keep dates as integers (4 bytes) – days since the unix epoch, and datetimes as integers (8 bytes) – microseconds since the unix epoch.

Questions:

  1. What’s the right way to convert a date to days since unix epoch? I found this: time.time()/86400 (python).
  2. Is it robust to keep datetimes as timestamps? What about the leap seconds – will this influence the accuracy? What if at some point in time a future date was stored as timestamp but later a leap second appeared?
  3. Any other issues?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:22:33+00:00Added an answer on May 27, 2026 at 9:22 pm
    1. time() / 86400 is fine. I’ve done this before; you should not anticipate any problems. You could also store time() truncated down to the nearest multiple of 86400, which might be a little nicer because you can pass it to various functions that already accept a time_t and have it come out as midnight UTC on the date in question.

    2. Don’t worry about leap seconds. Only specialized software takes them into account. The system date&time on all general purpose operating systems, and all general purpose date&time libraries pretend they don’t exist. Your NTP server implements them by just fudging the system clock ahead by one second whenever they happen.

    3. C’s gettimeofday returns the time as two separate 4-byte integer values: seconds since the epoch, and microseconds since the start of the second (struct timeval). Similarily, C’s clock_gettime returns the time as two separate 4-byte integer values: seconds since the epoch, and nanoseconds since the start of the second (struct timespec). If you care about compatibility with existing representations of time, you might choose one of those two formats instead of an 8-byte integer counting microseconds since the epoch. On the other hand both of those have the y2.038k bug (unless the first integer is extended to 8 bytes, for a total of 12 bytes) and they are less convenient to use in a database. So I think your idea of microseconds since the epoch is just fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need a way to allow sorting except for last item with in a list.
need ask you about some help. I have web app running in Net 2.0.
Need some help about with Memcache. I have created a class and want to
I have a universal view controller class which all of the view controller classes
I have a universal app with some localization. My problem is about splash screens.
I have a custom OS X NPAPI plugin built as universal 32 bit bundle.
I wonder if there is a universal way of resolving a path using a
I am building a universal wrapper for several different external sites that would build
I have some differential equations that I need to solve using MATLAB's ODE solvers.
Is there a way to retrieve schema owner of a store procedure from within

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.