Date format

I’m trying to change the date format to display in a Day, Month Year format using

- platform: time_date
  display_options:
    - 'date'
  value_template: '{{now().strftime("%A")}}, {{now().strftime("%B")}} {{now().strftime("%d")}}'

However it continually shows up as YYYY-MM-DD.

Suggestions on how to fix?

sensor:
  - platform: time_date
    display_options:
      - 'date'

  - platform: template
    sensors:
      date_template:
        friendly_name: 'Date'
        value_template: '{{ as_timestamp(now()) | timestamp_custom("%d/%m/%y", True) }}'

group:
  date_card:
    name: Date
    entities:
     - sensor.date_template
3 Likes

Thanks! That worked with a little tweaking of how I wanted the date format to work.

Glad you got want you want.

i have a sensor, sensor.meet_end

{{ states(‘sensor.meet_end’) }} displays - 2019-04-01 17:30:00

is there a way to template it to display - April 4th 2019 4:30pm

Sorry to post on a old thread, I thought it would be better then starting a new one.

Put this into Home Assistant’s Template Editor and it should produce 95% of what you requested:

{{as_timestamp(states('sensor.meet_end')) | timestamp_custom("%B %-d %Y %-I:%M%P", true) }}

The missing 5% is the th in 4th. That thing changes depending on the number (1st, 2nd, 3rd, 4th, 5th). Including it in the template is … more work than I’m willing to invest. :wink:

Be advised that you requested to convert 2019-04-01 17:30:00 to April 4th 2019 4:30pm. I assume you meant 5:30pm (the equivalent of 17:30). However if you really want the conversion to subtract one hour then this will do it:

{{(as_timestamp(states('sensor.meet_end')) - 3600)| timestamp_custom("%B %-d %Y %-I:%M%P", true) }}

First, Thanks for your help. Truly appreciate it!
Im sorry, I posted the wrong sensor, that’s why the time is off.
it should have been sensor.meet_start.

If I enter this into the template.

{{as_timestamp(states('sensor.meet_start')) | timestamp_custom('%B %-d %Y %-I:%M%P', 'true') }}

It doesn’t list anything, its blank.

I do use this to the the sufixes on my normal dates, so im sure ill figure something out for that.
{%- macro ordinal(num) %}
{%- set d = {1:‘st’,2:‘nd’,3:‘rd’} %}
{%- set num = num | int %}
{%- if 10 < num % 100 <= 20 %}
{{- num }}th
{%- else %}
{{- num }}{{ d.get(num % 10, ‘th’) }}
{%- endif %}
{%- endmacro %}
{{ ordinal(states(‘sensor.day_us’)) }}

EDIT: this did work,
{{as_timestamp(states('sensor.meet_start')) | timestamp_custom('%B %-d %Y %-I:%M%p', 'true') }}

Now onto the next task with the rd,th,st part :slight_smile: thanks again, I owe you one!