# Get Current Day of the Month and Write to a tag

**URL:** <https://forum.inductiveautomation.com/t/get-current-day-of-the-month-and-write-to-a-tag/19712>\
**Category:** Ignition\
**Created:** [September 18, 2018, 1:40pm UTC](https://forum.inductiveautomation.com/t/get-current-day-of-the-month-and-write-to-a-tag/19712 "2018-09-18T13:40:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [September 18, 2018, 1:40pm UTC](https://forum.inductiveautomation.com/t/get-current-day-of-the-month-and-write-to-a-tag/19712/1 "2018-09-18T13:40:25Z")

</div>

How do you get the current day of the month and write it to a tag in a gateway script?  
This is what I have so far

```auto
now = system.date.now()
dayOfMonth = system.date.getDayOfMonth(now)
system.tag.write("[default]CurrentDay")

```

---

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [September 18, 2018, 2:00pm UTC](https://forum.inductiveautomation.com/t/get-current-day-of-the-month-and-write-to-a-tag/19712/2 "2018-09-18T14:00:32Z")

</div>

> [@jshaffer09](#):
>
> system.tag.write("[default]CurrentDay")

This is setup to put out an integer. If your tag type is string remove the int()

```auto
today = system.date.now()
dayOfMonth = int(system.date.format(today, "dd"))
system.tag.write("[default]CurrentDay",dayOfMonth)

```

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [September 18, 2018, 2:17pm UTC](https://forum.inductiveautomation.com/t/get-current-day-of-the-month-and-write-to-a-tag/19712/3 "2018-09-18T14:17:37Z")

</div>

the value for the tag is still null.

---

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [September 18, 2018, 2:45pm UTC](https://forum.inductiveautomation.com/t/get-current-day-of-the-month-and-write-to-a-tag/19712/4 "2018-09-18T14:45:07Z")

</div>

what are you putting this script in?

```auto
today = system.date.now()
dayOfMonth = int(system.date.format(today, "dd"))
print dayOfMonth

```

If you put this in the script console it should print the number

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [September 18, 2018, 3:01pm UTC](https://forum.inductiveautomation.com/t/get-current-day-of-the-month-and-write-to-a-tag/19712/5 "2018-09-18T15:01:06Z")

</div>

this seems to be using system, make sure you have `import system` before the code maybe? I’m not a jython expert, you can also `import datetime`

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [September 18, 2018, 3:13pm UTC](https://forum.inductiveautomation.com/t/get-current-day-of-the-month-and-write-to-a-tag/19712/6 "2018-09-18T15:13:56Z")

</div>

this worked

```auto
dayOfMonth = system.date.getDayOfMonth(system.date.now())
system.tag.write("[default]CurrentDay",dayOfMonth)

```

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [September 19, 2018, 12:25pm UTC](https://forum.inductiveautomation.com/t/get-current-day-of-the-month-and-write-to-a-tag/19712/7 "2018-09-19T12:25:25Z")

</div>

If this is on a timer script, it seems like a bit of running around the mulberry bush to get what could be done as an expression tag.

```auto
dateFormat(now(),'d')

```
