Add date and time value into email containing html

I am sending an email containing a few html tables and have some sentences in html included in the email before the tables. I want to include current time and date formatted and then inserted into my html code. How would I do this? The only way I could think of is to create a dataset including the formatted date and time and include that in the html code but theres got to be a better way to do it. Here is my code related to the HTML part of the script.

	#get current date and time and format
	today = system.date.now()
	TimeF = system.date.format(today,"HH:mm:ss")
	DateF = system.date.format(today,"MM-dd-yyyy")
	
	
	###send email with html documents
	
	#define body of email in html
#	body1 = "<HTML><BODY><H1>Here is your daily report from yesterday</H1>"
#	body1 += "And this text is <font color='red'>red</font></BODY></HTML>"
	body1 = "<HTML><BODY><H1>Daily Status report of XXX System</H1>"
	body1 += "Attachments contain comma-separated data collected over the past 24 hours.<br><br>"
	body1 += "HTML reports are included in email body and plain text reports are attached.</BODY></HTML><br>"
	body1 += DIStatusHTML
	body1 += "<HTML><br><HTML>"
	body1 += DOStatusHTML
	body1 += "<HTML><br><HTML>"
	body1 += AIStatusHTML

No datasets or anything are needed - just use direct string interpolation.
You can also clean things up a lot using Python's multiline string literals and the format method:

	###send email with html documents
	body = """
		<html><body>
		<h1>Daily Status report of XXX System (generated {timestamp})</h1>
		Attachments contain comma-separated data collected over the past 24 hours.
		<br><br>
		HTML reports are included in email body and plain text reports are attached.
		<br>
		{diStatus}
		<br>
		{doStatus}
		<br>
		{aiStatus}
		</body></html>
	""".format(
		timestamp = system.date.format(system.date.now(), "MM-dd-yyyy HH:mm:ss"),
		diStatus = DIStatusHTML,
		doStatus = DOStatusHTML,
		aiStatus = AIStatusHTML,
	)
2 Likes

Forgot about the .format function...thanks! Worked perfect!