The official website documentation can use id (time_stntp). now(). strftime (“% Y% m% d”) to convert the current date to a string (such as “20241031”, which is a string, not a number). strftime can only be converted to a character type, not a number (integer type). In the ESPHome burning code, how to convert it to a numerical type (such as 20241031, which is a number, the difference is that it is not enclosed in double quotes)? I need to make a conditional judgment. The variable stores the date number, whether it is the current day or not, so I want to convert it to a number for easy processing. Do you know? I couldn’t find it in the official website documentation
I would say the easy way would be to use time stamps. Yeas, you could do some convertions but that is a lot of work and in the background it’s already stored as timestamp
id(time_stntp).now().timestamp
will return the current unix timestamp.
1 Like
Thank you, this is not what I wanted.
It is indeed not. But it is a better solution. Why don’t you want to do that?
it’s not really practical number “for easy processing”.
Unix timestamp, like septillion suggested, is more practical.
Or you could use:
to do your processing.
If you really need to use 20241031 as a number, try with
int my_date = atoi(x.c_str());
Thank you for your help, I understand now.