How to display Date Attribute?

Permalink 4 users found helpful
After creating a custom attribute of the type Date/Time........
how do you get it to show on a page??
getAttributeValue??
DisplayValue???

I am trying to arrive at something of this sort:
$cobj->getCollectionDatePublic('F j, Y');

but for a custom attribute of a page and not for the Date Public of the page.....


thanks

View Replies:
nickratering replied on at Permalink Reply
nickratering
Should be something like:
<?php
 if($c->getAttribute('thenameofthedateattribute')) {
echo strftime(" %d-%m-%Y",strtotime($c->getAttribute('thenameofthedateattribute')));
 }
?>

?
psd2concrete5 replied on at Permalink Reply
+1

I am also looking something like this....

Any help will be appreciated.
MrKDilkington replied on at Permalink Reply
MrKDilkington
You could try this.

$c->getCollectionAttributeValue('attribute_name')

Are you trying to display a custom attribute in a template file?
psd2concrete5 replied on at Permalink Reply
Hello MrKDilkington,

Thanks for reply, i have create date attribute and i want that when i select this attribute via custome attributes i want to alert selected date in this format " YYYY,MM,DD" but below code only alert "year"

<?php
            if ($c->getAttribute('mydate')) {
            $mydatevalue = strftime("%Y,%m,%d",strtotime($c->getAttribute('mydate')));
            echo $mydatevalue;   
            echo '<script type="text/javascript">alert('.$mydatevalue.');</script>';
            } ?>
MrKDilkington replied on at Permalink Reply
MrKDilkington
The problem is you are missing a set of quotes in the alert.

<?php
if ($c->getAttribute('mydate')) {
    $mydatevalue = strftime("%Y,%m,%d",strtotime($c->getAttribute('mydate')));
    echo $mydatevalue;
    echo "<script>alert('" . $mydatevalue . "');</script>";
}
?>

As a side note - type="text/javascript" is not required in <script> tags, by default the type will be JavaScript.
psd2concrete5 replied on at Permalink Reply
Hello MrKDilkington,

Thanks a lottt. It works for me.
psd2concrete5 replied on at Permalink Reply
Hi MrKDilkington,

One more question hope you can help me....

I have place below code to add attribute via controller...actually i only require "Date " field not Hour,Min, AM-PM field so is this possible only i can add "Date" Field...

$mydate = CollectionAttributeKey::getByHandle('mydate1');
      if (!$commingdate instanceof CollectionAttributeKey) {
         $commingdate = CollectionAttributeKey::add("date", array(
           'akHandle' => 'mydate1',           
           'akName' => t('Date1')), $pkg);
      }
psd2concrete5 replied on at Permalink Reply
Sorry, i have change my code...

$mydate = CollectionAttributeKey::getByHandle('mydate1');
      if (!$mydate instanceof CollectionAttributeKey) {
         $mydate = CollectionAttributeKey::add("date", array(
           'akHandle' => 'mydate1',           
           'akName' => t('Date1')), $pkg);
      }
MrKDilkington replied on at Permalink Reply
MrKDilkington
I am afraid I don't have experience doing this.

Maybe someone else will know.
psd2concrete5 replied on at Permalink Reply
Hi ,

Don't be afraid :), thanks for the reply...
psd2concrete5 replied on at Permalink Reply
Hello MrKDilkington,

I got the answer, here it is, hope it will help someone too...

Just adding below array, we can get only date picker instead or date and time...

'akDateDisplayMode' => 'date'



$mydate = CollectionAttributeKey::getByHandle('mydate1');
      if (!$mydate instanceof CollectionAttributeKey) {
         $mydate = CollectionAttributeKey::add("date", array(
           'akHandle' => 'mydate1',           
           'akName' => t('Date1'),
           'akDateDisplayMode' => 'date'), $pkg);
      }