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

  • Home
  • SEARCH
  • 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 231861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:58:07+00:00 2026-05-11T19:58:07+00:00

I usually store dates as integers using PHP’s time() function in a MySQL database

  • 0

I usually store dates as integers using PHP’s time() function in a MySQL database rather than using MySQL’s date format simply because it’s easier to manipulate when I pull it back out, but are there any disadvantages to this?

  • 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-11T19:58:07+00:00Added an answer on May 11, 2026 at 7:58 pm

    Range:

    There’s always the obvious disadvantage: The range that you can store is limited från 1970 to 2038. If you need to store dates outside of this range, you’ll generally need to use another format. The most common case I’ve found where this apply is to birthdates.

    Readability:

    I think that the most important reason that people chose to use one of the built-in date-types it that the data is easier to interpret. You can do a simple select, and understand the values without having to format the response further.

    Indexes:

    A good technical reason to use the date types is that it allows for indexed query in some cases that unix timestamps doesn’t. Consider the following query:

    SELECT * FROM tbl WHERE year(mydate_field) = 2009;
    

    If mydate_field is of a native date type, and there’s an index on the field, this query will actually use an index, despite the function call. This is pretty much the only time that mysql can optimize function calls on fields like this. The corresponding query on a timestamp field won’t be able to use indices:

    SELECT * FROM tbl WHERE year(from_unixtime(mytimestamp_field)) = 2009;
    

    If you think about it for a bit, there’s a way around it, though. This query does the same thing, and will be able to use index optimizations:

    SELECT * FROM tbl WHERE mytimestamp_field > unix_timestamp("2009-01-01") AND mytimestamp_field < unix_timestamp("2010-01-01");
    

    Calculations:

    Generally, I store dates as unix time, despite the disadvantages. This isn’t really based on it’s merits, but rather it’s because I’m used to it. I’ve found that this simplifies some calculations, but complicate others. For example, it’s very hard to add a month to a unix timestamp since the number of seconds per month varies. This is very easy using the mysql DATE_ADD() function. However, I think that in most cases it actually simplifies calculations. For example, it’s quite common that you want to select the posts from, say, the last two days. If the field contains a unix timestamp this can be done easily by simply doing:

    SELECT * FROM tbl WHERE mytimestamp_field > time() - 2*24*3600;
    

    It’s probably a matter of taste, but I personally find this faster and easier than having to rember the syntax of a function such as DATE_SUB().

    Timezones:

    Unix timestamps can’t store time zone data. I live in sweden which has a single timezone, so this isn’t really a problem for me. However, it can be a major pain if you live in a country that spans multiple timezones.

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

Sidebar

Ask A Question

Stats

  • Questions 137k
  • Answers 137k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It sounds like you are still having a lot of… May 12, 2026 at 7:17 am
  • Editorial Team
    Editorial Team added an answer The Mobile Device Browser File might be of some help.… May 12, 2026 at 7:17 am
  • Editorial Team
    Editorial Team added an answer You can use Marshal.ReleaseComObject e.g. if(Marshal.IsComObject(oGE)==true) { Marshal.ReleaseComObject(oGE); } May 12, 2026 at 7:17 am

Related Questions

I usually store dates as integers using PHP's time() function in a MySQL database
I build for more than two dozen targets from a source tree with usually
I am looking for best practices for creating collections made from anonymous types. There
When I generate sql schema creation scripts manually I usually just call 'Create Procedure...',
I Have a cursor in stored procedure under SQL Server 2000 (not possible to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.