By frdesign on
My custom module uses data which is seen in a views tab when viewing a node. One of the fields on my custom table is a unix timestamp. How do I turn the unix timestamp into human readable date when the view query is executed? Is there a way to grab the results from a view query and do stuff to them before it's presented to the viewer?
Comments
Views 1 or 2? And it sounds
Views 1 or 2?
And it sounds like you have already described the table(s) and fields for views, is that correct?
Oops
Sorry about that, Views 2. Yes, I have described the tables. I still think it's voodoo how views api works, so cool! Can you tell I'm a noob to programming :->.
My view works great when I test it in Views admin. I'd just like to replace the begin_date and end_date fields with real dates. I'm guessing I'd have to grab the returned values before they're displayed, do my magic to them, and display the new value instead. Is this even possible?
Part of describing tables to
Part of describing tables to views is defining the fields, so you would have something like this
for both begin_date and end_date fields. You can set the handler to a custom handler which implements the render function to format the date.
Date handler
So I did a bit of research on custom handlers for views since I have no clue how to make one. It turns out the views module already comes with a views_handler_field_date class. So all I had to do was replace 'views_handler_field_numeric' with 'views_handler_field_date' in my table description code and views admin automatically gives me a couple of options for formatting my Unix timestamps into real dates. Thanks for pointing me in the right direction!
Get rid of hours, minutes
Now that I have human readable dates in my custom table's view I want to customize the date display. Currently all dates are showing date plus hours & minutes (Friday, June 5, 2009 - 00:00). In my case I only want to show the date (Friday, June 5, 2009). Is it possible to get rid of minutes and seconds in my view's date display?
After some digging I found
After some digging I found the following info about this views hook:
I figured I could get the returned values before viewing and remove the hours/seconds info with a php string function. Does this sound like a bad idea to anyone?