# Add date and time value into email containing html

**URL:** <https://forum.inductiveautomation.com/t/add-date-and-time-value-into-email-containing-html/65728>\
**Category:** Ignition\
**Created:** [October 26, 2022, 8:41pm UTC](https://forum.inductiveautomation.com/t/add-date-and-time-value-into-email-containing-html/65728 "2022-10-26T20:41:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [October 26, 2022, 8:41pm UTC](https://forum.inductiveautomation.com/t/add-date-and-time-value-into-email-containing-html/65728/1 "2022-10-26T20:41:23Z")

</div>

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.

```auto
	#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

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 26, 2022, 9:03pm UTC](https://forum.inductiveautomation.com/t/add-date-and-time-value-into-email-containing-html/65728/2 "2022-10-26T21:03:57Z")

</div>

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](https://pyformat.info/):

```python
	###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,
	)

```

---

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [October 26, 2022, 9:22pm UTC](https://forum.inductiveautomation.com/t/add-date-and-time-value-into-email-containing-html/65728/3 "2022-10-26T21:22:46Z")

</div>

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