# Button-card - comment afficher un attribut date "formaté"?

**URL:** <https://forum.hacf.fr/t/button-card-comment-afficher-un-attribut-date-formate/26515>\
**Category:** Entraide Home Assistant\
**Created:** [Août 6, 2023, 9:34 UTC](https://forum.hacf.fr/t/button-card-comment-afficher-un-attribut-date-formate/26515 "2023-08-06T09:34:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christophe69480](https://forum.hacf.fr/user_avatar/forum.hacf.fr/christophe69480/32/110253_2.png) [@Christophe69480](https://forum.hacf.fr/u/Christophe69480)\
**Post date:** [Août 6, 2023, 9:34 UTC](https://forum.hacf.fr/t/button-card-comment-afficher-un-attribut-date-formate/26515/1 "2023-08-06T09:34:29Z")

</div>

Bonjour

je me bat avec button-card pour quelque chose de basique mais je n'y arrive pas.

j'ai un sensor qui me donne la date de derniere sauvegarde  
 ![image](https://forum.hacf.fr/uploads/default/original/3X/5/f/5ff11a225c053db50ab073cf0c62b11fa9ee7ada.png)

```auto
type: custom:button-card
entity: sensor.samba_backup
name: Date derniere Sauvegarde
show_state: false
show_icon: false
label: '[[[return entity.attributes.last_backup]]]'
show_label: true

```

mais je voudrais le mettre en forme de la manière suivante

 ![image](https://forum.hacf.fr/uploads/default/original/3X/7/0/7032cc117a675955f99215cf51e88e876f9a28d8.png)

je n'arrive pas à faire afficher cette formule dans button-card

```auto
{{as_timestamp(states['sensor.samba_backup'].attributes.last_backup) | timestamp_custom('le %d %m %Y à %H:%M')}}

```

j ai essayé state\_display et label mais je dois mal m'y prendre

par avance merci de votre aide

---

<div class="post-metadata">

**Author:** ![WarC0zes](https://forum.hacf.fr/user_avatar/forum.hacf.fr/warc0zes/32/137471_2.png) [@WarC0zes](https://forum.hacf.fr/u/WarC0zes)\
**Post date:** [Août 6, 2023, 10:25 UTC](https://forum.hacf.fr/t/button-card-comment-afficher-un-attribut-date-formate/26515/2 "2023-08-06T10:25:26Z")

</div>

> [@Christophe69480](#):
>
> `as_timestamp(states['sensor.samba_backup'].attributes.last_backup) | timestamp_custom('le %d %m %Y à %H:%M')}}`

Bonjour,  
une solution sur le forum us [Button card addon and as\_timestamp problem - Configuration - Home Assistant Community](https://community.home-assistant.io/t/button-card-addon-and-as-timestamp-problem/501345)

exemple:

```auto
  info2: |
    [[[
      var data_temp_max = new Date(states['sensor.record_temperatura_massima'].attributes.quando);
      return `<ha-icon
        icon="mdi:calendar"
        style="width: 20px; height: 20px; color: white;">
        </ha-icon><span> registrata il: <span style="color: var(--text-color-sensor);">${data_temp_max.toLocaleDateString()} alle ore ${data_temp_max.toLocaleTimeString()}</span></span>`
    ]]]

```

---

<div class="post-metadata">

**Author:** ![Christophe69480](https://forum.hacf.fr/user_avatar/forum.hacf.fr/christophe69480/32/110253_2.png) [@Christophe69480](https://forum.hacf.fr/u/Christophe69480)\
**Post date:** [Août 6, 2023, 2:21 UTC](https://forum.hacf.fr/t/button-card-comment-afficher-un-attribut-date-formate/26515/3 "2023-08-06T14:21:57Z")

</div>

merci pour le lien, mais je n'ai pas reussi à reproduire

j'ai cherché sur le forum, il y a de nombreux sujet la dessus mais aucun sur la date dans un attribut  
c'est dingue qu'il n'y ait pas un moyen simple de formater une date  
au final je suis passé par un Neme Template

je poste si ca peut depanner quelqu'un

```auto
- sensor :
     - name: 'Date derniere sauvegarde'
       unique_id: sensor.lastsave
       state: "{{ state_attr('sensor.samba_backup', 'last_backup') | as_timestamp | timestamp_custom('Le : %d %m %Y à %H:%M') }}"

```

mon button card :

```auto
type: custom:button-card
entity: sensor.date_derniere_sauvegarde
name: Date derniere Sauvegarde
show_state: true
show_icon: false

```

le resultat  
 ![image](https://forum.hacf.fr/uploads/default/original/3X/d/d/dd99034fec983c0fc97a34a6f33329079949c0c1.png)

si quelqu'un à une solution plus simple sans template, je prend 😉

---

<div class="post-metadata">

**Author:** ![WarC0zes](https://forum.hacf.fr/user_avatar/forum.hacf.fr/warc0zes/32/137471_2.png) [@WarC0zes](https://forum.hacf.fr/u/WarC0zes)\
**Post date:** [Août 6, 2023, 4:45 UTC](https://forum.hacf.fr/t/button-card-comment-afficher-un-attribut-date-formate/26515/4 "2023-08-06T16:45:55Z")

</div>

Avec button-card et helpers c’est bon.

```auto
type: custom:button-card
entity: sensor.samba_backup
aspect_ratio: 1/1
show_state: true
show_label: true
label: |
  [[[return helpers.formatDateTime(entity.attributes.last_backup)]]]

```

options possible de formatage:

```auto
Date, Time and Date Time format helpers, all localized (takes a string or a Date object as input):
helpers.formatTime(time): 21:15 / 9:15
helpers.formatTimeWithSeconds(time): 9:15:24 PM || 21:15:24
helpers.formatTimeWeekday(time): Tuesday 7:00 PM || Tuesday 19:00
helpers.formatTime24h(time): 21:15
helpers.formatDateWeekdayDay(date): Tuesday, August 10
helpers.formatDate(date): August 10, 2021
helpers.formatDateNumeric(date): 10/08/2021
helpers.formatDateShort(date): Aug 10
helpers.formatDateMonthYear(date): August 2021
helpers.formatDateMonth(date): August
helpers.formatDateYear(date): 2021
helpers.formatDateWeekday(date): Monday
helpers.formatDateWeekdayShort(date): Mon
helpers.formatDateTime(datetime): August 9, 2021, 8:23 AM
helpers.formatDateTimeNumeric(datetime): Aug 9, 2021, 8:23 AM
helpers.formatDateTimeWithSeconds(datetime): Aug 9, 8:23 AM
helpers.formatShortDateTime(datetime): August 9, 2021, 8:23:15 AM
helpers.formatShortDateTimeWithYear(datetime): 9/8/2021, 8:23 AM

```

---

<div class="post-metadata">

**Author:** ![Christophe69480](https://forum.hacf.fr/user_avatar/forum.hacf.fr/christophe69480/32/110253_2.png) [@Christophe69480](https://forum.hacf.fr/u/Christophe69480)\
**Post date:** [Août 6, 2023, 5:05 UTC](https://forum.hacf.fr/t/button-card-comment-afficher-un-attribut-date-formate/26515/5 "2023-08-06T17:05:48Z")

</div>

ah excellent !!!! merci beaucoup !!!  
j'ai meme le mois en francais

j'avais vu la fonction dans la doc mais je mettais pas return devant donc je ne suis pas arrive a le faire  
 ![image](https://forum.hacf.fr/uploads/default/original/3X/5/d/5d2a38f43f2de6d190bcc7cdf59212d59e4fb7c7.png)
