Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Dates on database
  • Perhaps it's not the proper place to post this question, but since I've read in other posts users saying date fields in database tables should be in Int format (some Auth discussions and others), I want to know why this preference.
    As far as I can see, there are more problems than advantages using Ints instead of dates.
    - When taking the value from a 'human' form, you can't use the post value without converting it first
    - Querys involving date parts (ex: get blog entries for a year or month) implies extensive data manipulation before the query
    - Timestamps are not suitable for birthdays, if your want to get accurate information from old people (like me). Thanks in advance for your responses.
  • - When taking the value from a 'human' form, you can't use the post value without converting it first
    I don't know what you do, but I'd convert the date either way - the full mysql timestamp isn't all that friendly either. PHP uses timestamps internally anyway in the end so if you convert it makes it faster to input the int instead of having to do 2 conversions (mysql -> timestamp -> your format).
    - Querys involving date parts (ex: get blog entries for a year or month) implies extensive data manipulation before the query
    Look into strtotime() and it becomes incredibly easy to build such a query. Also you can use mysql's date conversion to convert the unix timestamp to something else before querying it.
    - Timestamps are not suitable for birthdays, if your want to get accurate information from old people (like me).
    Most modern servers a probably 64 bit, but even if they're not this is what the PHP manual says about the range for 32bit: "The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT." - I really doubt you're that old. In the end I use either timestamps (for example unsigned int for created-at/updated-at) and for birthdates I use just YYYY-MM-DD as that sorts easily and is easily converted to anything else while also allowing me to select a specific month independent of the year. Also time and timezone have no meaning for birthdates, thus useless to save.
  • Thanks Jelmer, clear as always. Probably I mixed up unix and mysql timestamps when saying they are not suitable for birthdays (besides I made my first website with an abacus and a marble stone).

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion