56

When I am looking to create some timestamp fields (or other date/time style fields), what is the best way to name them? Should I just put record_timestamp?

10 Answers 10

40

You should describe the purpose of the column and not necessarily the data type. You can include date/time/timestamp in the name, but you should also include the meaning. For example

  • CreationDate
  • StartDate
  • StatusTime
  • Accessed
  • Updated

Adding Date/Time/Timestamp and such at the end is particularly useful when the abscence of the addition would conflict with another column. For example, a table may need both a Status and a StatusTime.

  • 2
    Just to add my two cents. I worked with many legacy MRP systems and found CreatedOnUtc and UpdatedOnUtc used often. – Geovani Martinez Sep 20 '16 at 1:40
  • 4
    I think "Accessed" and "Updated" can be ambiguous, since it can also imply boolean (at least in Ruby world) – Artur Beljajev Jun 2 '17 at 13:26
  • 2
    @GeovaniMartinez that can be confusing, as a lot of SQL databases, PostgreSQL included, store at UTC and read in client's timezone. – Evan Carroll Jun 2 '17 at 14:11
  • And if the time unit is supposed to be UTC vs System Local then specify _UTC in the column name. Thank you from all of us who must maintain the code later. – Jonathan Fite Jan 30 '18 at 17:55
  • Accessed and Updated could be ambiguous with WHO accessed or updated, which is a fairly common thing to track – Joe Phillips Mar 20 '18 at 15:56
26

How about xyz_at for a timestamp and xyz_on for a date field - eg start_at or start_on?

Normally I'd avoid including the data type in the field name - much better if you can infer what you need to know about the type from the name of any field (a field called description is unlikely to be an integer) - but being able to tell the difference between a timestamp and a date is often helpful.

15

I use:

  • created_at
  • updated_at
  • 2
    "at" can imply location too. What about "when" instead of "at"? – Sepster Oct 22 '13 at 1:12
  • 1
    "at" or "as at" is used frequently in legal and financial documents to refer to when something happened. english.stackexchange.com/questions/112770/… – Neil McGuigan Dec 19 '13 at 19:05
  • 3
    It can still be ambiguous. What if you need to know the time and location at which is was updated? updated_at could be either. But I think the answer is, as always with naming, use the most concise name that removes all realistic ambiguity. I.e. if in a particular context there is potential for a certain confusion, eliminate it, but don't use names that are more verbose than is required for that – nafg Mar 17 '17 at 0:22
  • 1
    how about "on". Although it implies a date more than a time, it's still pretty obvious – Joe Phillips Mar 20 '18 at 15:57
6

I looked at your profile and it says you work with SQL Server and in SQL Server TIMESTAMP data type has nothing to do with date or time and its used to kind of version stamping the rows. This is very useful in identifying which rows have been modified from a given point of time.

If you use TIMESTAMP then you don't have to specify a column name and SQL Server will create a column "TimeStamp" for you. But it is recommended to use "ROWVERSION" data type and in this case you have to specify the column name.

What's the best name for a column like this? It depends, and I would use something like VersionStamp, RV etc... What I consider important is NOT how you name it but are you using that consistently across the board.

HTH

Ref: http://msdn.microsoft.com/en-us/library/ms182776(v=sql.90).aspx

http://msdn.microsoft.com/en-us/library/ms182776.aspx

3

I found that using column names such as create_time, update_time and expire_time leads to better readability when it comes to method naming and specs (RSpec).

1

I prefer to use a prefix of DT for date stamps. For example: DTOpened, DTClosed, DTLastAccessed. This lets me list out all the DTxxxx for a quick reference of all date stamps in a given table.

1

I work for Texas Instruments, and on their systems they use xxxx_dttm

0

I would used a meaningful prefix and _TSMP as a suffix e.g. CREATION_TSMP or LAST_UPDATE_TSMP

0

I prefer using conventions that already exist.

Unix and programming languages have a widely accepted convention of mtime for Modification Time

For creation time,

  • BSD and Windows use birthtime
  • Windows also uses Creation Time
  • xstat uses btime
  • ext4 uses crtime
  • JFS and btrfs use otime (don't ask, guessing "origination").

So for me, I pick mtime, and crtime for meta data.

For user supplied data, I go with what the field represents. If it's a birthday, I just say user_birthday.

As far as precision, for some it seems to hang them up on too much precision. You can store your birthdate as a timestamp (after all you were technically birthed at a time of day), but the SQL spec has casts from higher-precision to lower precision so if you're using a decent database this shouldn't be an issue. In your app itself, you can always truncate when needed. That is to say, I would never go birthday_date.

0

In order to maintain consistency accross column names, I would suggest you to the following syntax:

dateCreated
dateUpdated
dateAccessed
dateStarted
date...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.