1

I'm confused. I'm using a Global: PHP field inside a view to tweak the output of the row based on the date value of a certain field.

print (strtotime((string)$row->field_date));

Doesn't seem to return anything.

print $row->field_date;

Returns "Tuesday, December 1, 2015"

print strtotime('Tuesday, December 1, 2015');

Returns 1448956800

I've tried converting the $row object to an array just for fun with get_object_vars($row) but that didn't work either.

In my case I expect that print (strtotime((string)$row->field_date)); returns the value (unix timestamp) 1448956800.

2
  • and the desired output is? Dec 2, 2015 at 15:08
  • I'd expect print (strtotime((string)$row->field_date)); to print a unix timestamp like 1448956800. That is what I desire. Dec 2, 2015 at 16:17

1 Answer 1

1

$row->field_date contains markup, not just the date/string value hence strtotime() won't/can't return a valid unix timestamp. To fix, try using strip_tags() around the returned value of $row->field_date like:

strtotime(strip_tags((string)$row->field_date));

or use "Strip HTML tags" option checkbox under "Rewrite Results" in the "Configure field" dialog.

3
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
    – digital
    Dec 2, 2015 at 17:09
  • @digital Have another look, this does appear to answer the question
    – Clive
    Dec 2, 2015 at 17:34
  • I've added more detail. I did feel that I was clearly answering the question. Dec 2, 2015 at 17:36

Your Answer

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

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