I'm working with a Drupal 8.3.6 setup done by someone else and I have a date format that doesn't make sense to me. I'm interacting with it thru MySQL Workbench. The best I can tell, 1499287512 = Wed, 07/05/2017 - 23:02 and 1501079338 = Tue, 08/22/2017 - 06:25 BUT there's no guarantee of that. In any event, 1499287512 and 1501079338 appear to be in a date placeholder; numbers like it appear in users_field_data.fields, created, changed, access, login.


Those are dates stored as Unix timestamps, which are essentially the number of seconds since midnight, January 1st, 1970 UTC (the epoch is 1970-01-01T00:00:00+00:00).

As far as Drupal is concerned, they are proper fields on those entities, either TimestampItem, CreatedItem, or ChangedItem fields.

Keep in mind that the timestamp always refers to that epoch and always is referenced to UTC; there is no real thing as a Unix timestamp in a local time zone. When working with them in Drupal it is always best to use DrupalDateTime objects, and use it methods for computation (which will inherit from \DateTime).

| improve this answer | |
  • Thank you, I used from_unixtime() as described in stackoverflow.com/questions/6267564/… -- what do you mean about DrupalDateTime objects? You mean working with them w/in Drupal in PHP? – seizethecarp Dec 14 '17 at 19:41
  • 1
    @seizethecarp FROM_UNIXTIME() is going to rely on the time zone of the MySQL server, not necessarily the user. DrupalDateTime objects are for PHP. It isn't really advisable to use database values directly; leverage the appropriate Drupal API. – mpdonadio Dec 14 '17 at 20:33

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.