I am displaying webform submissions in a view, and need to add a "NEW" notification if the submission is less than a day old.
I have created views-view-field--myfield.tpl.php and have managed to change the value of my field using the template.
I am grabbing the submitted date, which I have printed already to make sure it works, and it comes up as 13/05/2014 - 23:13
I am then trying to figure out how to return a value for a date that is less than 1 day old. I'm pretty sure the following should do it, but it always renders "not new".
<?php
$submitted = $view->style_plugin->rendered_fields[$view->row_index]['submitted'];
if( $submitted > strtotime('-1 day') ) {
echo '<div style="color:red;">NEW!</div>';
}
else
{
echo 'not new';
}
?>
Can anyone see where I'm going wrong?
UPDATE:
So, this works...
if( strtotime('14 May 2014') > strtotime('-1 day')) {
echo '<div style="color:red;">NEW!</div>';
}
else
{
echo 'nothing <br />';
}
If i set it to 14th may (today) Its shows up as NEW! , any earlier, it prints nothing.
So, this leads me to believe there is a problem with my submitted date.
But, If I put echo $submitted;
i get 13/05/2014 - 23:13
If I put $newDate = date("d M Y", strtotime($submitted)); echo $newDate;
i get 01 Jan 1970
for every result.
And If I put $newDate = date("d M Y", $submitted); echo $newDate;
I also get 01 Jan 1970
for every result.
So now I don't know what's going on. If its not in timestamp format, strtotime should sort it shouldnt it?