Hi Guys, i’ve created a card with some code i found on here but i cant find the page where i found it now.
It’s to display the time and date on a sidebar i’m trying to create.
The code below works great but displays as
11:32
Friday, 24 2021
but i’m trying to work out how to have it display as
11:32
Friday 24th December
Could anyone point me in the right direction or is there a better way of doing it as a sensor maybe
Thanks
It doesn’t make sense.
The code you posted should output the month before the year, but it doesn’t (according to you).
The only thing I can think of is that the month is written as month[now().strftime('%-m') when it probably should be without the - in %-m.
That is the only thing I can think of that the month is read as a negative number and that doesn’t exist in the array.
however the reason why the month didn’t show up correctly in yours is because the “%-m” returns the month as a number of 1 thru 12. your array will be accessed via it’s index number which goes from 0 thru 11. there is no array index 12 so it renders nothing.
you can try it with substituting a hard coded value in the template for the month as 11 (works) and as 12 (doesn’t work).
Thanks for the replies guys.
I’ve just copied this code over and that displays great thanks, do you know how i can add the 2 digits after the day so 24th, 1st etc.
I tried looking through here to work it out but can’t see mention of that.
Hi i finally had chance to add this and it works great.
Could you help me with the formatting please.
I’m now trying to force a line break so the day of the week is on the top line then the date and month the line underneath so…
Sunday,
26th December
And also the line spacing, as you can see they the lines are too close but i can’t work out where to put the padding or margin etc.
i tried adding the
to your code but it just disappears no matter where on the line i tried <div class="date">{{now().strftime('%A') ~ ', ' ~ display_date ~ ' ' ~ <p>now().strftime('%B ')<p> }}</div>
Lastly i’m wanting to make the date move closer to the time as well would that be in the card mod options?
Sorry for all the daft questions
Thanks
Thanks i couldn’t get that to display how i wanted on 2 lines for some reason.
After some work on the Here i managed to get it how i wanted using this line with your other code. <div class="date"><p>{{now().strftime('%A')}},</p><p>{{display_date}} {{now().strftime('%B')}}</p></div>