# Convert INTEGER into DATE

**URL:** <https://forum.inductiveautomation.com/t/convert-integer-into-date/71600>\
**Category:** Ignition\
**Created:** [March 26, 2023, 6:23pm UTC](https://forum.inductiveautomation.com/t/convert-integer-into-date/71600 "2023-03-26T18:23:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sammyjoe.gingras](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@sammyjoe.gingras](https://forum.inductiveautomation.com/u/sammyjoe.gingras)\
**Post date:** [March 26, 2023, 6:23pm UTC](https://forum.inductiveautomation.com/t/convert-integer-into-date/71600/1 "2023-03-26T18:23:37Z")

</div>

Hi, I would like extract some information of an integer's tag to rewrite it as a date format. I need to write it on the gateway event in script.  
Ex: Integer = 20221008. I want to show it as 2022 10 08.  
Could somebody help me fix this please ?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [March 26, 2023, 8:48pm UTC](https://forum.inductiveautomation.com/t/convert-integer-into-date/71600/2 "2023-03-26T20:48:34Z")

</div>

I think you mean "extract some information from an integer tag".

Try this in the script console:

```auto
i = str(20221008)
# Note that month is zero based.
d = system.date.getDate(int(i[0:4]), int(i[4:6]) - 1, int(i[6:]))
print d
print system.date.format(d, "yyyy-MM-dd")

```

This results in

```auto
Sat Oct 08 00:00:00 BST 2022
2022-10-08

```

A couple of things to note.

- Keeping dates as date types will save you a lot of trouble. Format them at the last moment for display or reporting.
- Observe standards. As far as I know "yyyy-mm-dd" format always uses '-' hyphens. "dd/mm/yyyy" and "mm/dd/yyyy" always use '/' slashes.

[https://docs.inductiveautomation.com/display/DOC81/system.date](https://docs.inductiveautomation.com/display/DOC81/system.date)

---

<div class="post-metadata">

**Author:** ![mcgheeiv](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@mcgheeiv](https://forum.inductiveautomation.com/u/mcgheeiv)\
**Post date:** [March 26, 2023, 9:05pm UTC](https://forum.inductiveautomation.com/t/convert-integer-into-date/71600/3 "2023-03-26T21:05:41Z")

</div>

Similar to the last post, but I would use system.date.parse(str(int\_value), 'yyyyMMdd') instead of getDate....

[https://docs.inductiveautomation.com/display/DOC81/system.date.parse](https://docs.inductiveautomation.com/display/DOC81/system.date.parse)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [March 26, 2023, 9:29pm UTC](https://forum.inductiveautomation.com/t/convert-integer-into-date/71600/4 "2023-03-26T21:29:57Z")

</div>

Excellent. I had read the manual for that function but missed the point of it. It's much better to use the built-in functions where possible.

---

<div class="post-metadata">

**Author:** ![sammyjoe.gingras](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@sammyjoe.gingras](https://forum.inductiveautomation.com/u/sammyjoe.gingras)\
**Post date:** [March 27, 2023, 7:59pm UTC](https://forum.inductiveautomation.com/t/convert-integer-into-date/71600/5 "2023-03-27T19:59:47Z")

</div>

Thank, I forget to said that I want to write it in jython

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [March 27, 2023, 8:27pm UTC](https://forum.inductiveautomation.com/t/convert-integer-into-date/71600/6 "2023-03-27T20:27:08Z")

</div>

> [@sammyjoe.gingras](#):
>
> I forgot to say that I want to write it in Jython.

That _is_ Jython. It runs in Script Console and you can use the code in your scripts.

Here is the improved version to test in Script Console.

```auto
int_value = str(20221008)
# Note that month is zero based.
date_value = system.date.parse(str(int_value), 'yyyyMMdd')
print date_value
print system.date.format(date_value, "yyyy-MM-dd")

```
