0

I've inherited a project that deals with Drupal Facet API. I've got everything working fine, except for the display of the date for events.

The filter by date and time >> start date displays the date in seconds, however I would like this to be the date and time, e.g. Saturday 14th September 10:15 am

enter image description here

Here is the code from the event_system.module:

     if (isset($variables['view']) && $variables['view']->name == 'events') {
    $i = $variables['view']->row_index;
    $timestamp = strtotime($variables['view']->result[$i]->field_data_field_date_and_time_field_date_and_time_value);
    $variables['post_date'] = format_date($timestamp, 'medium');
  }

I've tried this:

$variables['post_date'] = format_date($timestamp, 'custom', 'g:i a, d F, Y',0);

and this:

$variables['post_date'] = format_date('l jS F Y', strtotime($timestamp));

I've tried adding different parameters to format_date but with no success. If someone could point me in the right direction that would be great.

1
  • Is it something I said, or indeed didn't say???? Sometimes it's hard to describe what the problem is when you're not entirely sure how it was developed. Ahhh the joys of being landed with something not of your making. I'm not a Back-End Dev, so finding it difficult. If anyone could help, or give some snippet of advice.
    – snarf1974
    Commented Feb 18, 2019 at 12:48

1 Answer 1

0

So it sounds like the issue is you need to convert a UNIX timestamp to a human-readable datetime? PHP comes with the date() function which can handle this.

The first argument is the 'format' which you can find here: http://php.net/manual/en/function.date.php.

The second argument is the UNIX timestamp--just simply pass in the timestamp variable (the # of seconds) as the second argument.

1
  • @ cchoe1 - Thanks for pointing me in the right direction. I've added in code a couple of attempts to get the date to display, but alas it is still showing the date in seconds (1568452500 etc). I'm really flying in the dark here! Had a look at the line above which is $timestamp = strtotime($variables['view']->result etc, but really don't know what is going on.... help!
    – snarf1974
    Commented Feb 19, 2019 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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