I have time data provided from a Home Assistant input_datetime entity. It’s in (hh:mm:ss) format. How do I convert this to (h:mm A) format? The rule returns the evaluation error below.
You’re missing a comma after the variable.
formatDate($PoolStartTime1, 'hh:mm A')
formatDate()
converts a date into a formatted string
It sounds like you first want to go the other direction and parse a formatted string into a date, so you would want to use the date()
function.
You’ll want to use an appropriate format in each direction. It looks like your string might be in hh:mm:ss
format. Note the double hh
and double mm
since each of these values appear to be 0 padded. Keep in mind that this will return a date which is output as a number of milliseconds (unix timestamp).
date("06:02:00", "hh:mm:ss")
⇒ 1680001320000
You could then format this back into your preferred date string using formatDate()
using your desired output format:
dt = date("06:02:00", "hh:mm:ss")
formatDate(dt, "h:mm A")
⇒ “6:02 AM”
Works perfectly! I see the flaw in my logic. Thanks much!