# Datetime format problem

**URL:** <https://forum.inductiveautomation.com/t/datetime-format-problem/56608>\
**Category:** Ignition\
**Created:** [February 28, 2022, 8:33am UTC](https://forum.inductiveautomation.com/t/datetime-format-problem/56608 "2022-02-28T08:33:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![eren.uyanik](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/eren.uyanik/32/30923_2.png) [@eren.uyanik](https://forum.inductiveautomation.com/u/eren.uyanik)\
**Post date:** [February 28, 2022, 8:33am UTC](https://forum.inductiveautomation.com/t/datetime-format-problem/56608/1 "2022-02-28T08:33:55Z")

</div>

Hello all,

I need add extra minutes on datetime.now(). I’m trying a script in the below but it doesn’t work because of time sctructure of datetime.

```auto
import datetime
time_format = '%Y-%m-%d %H:%M:%S'

pitchStartTime = datetime.datetime.utcnow()
print(pitchStartTime)
pitchEndTime = (pitchStartTime + datetime.timedelta(minutes=5))
print(pitchEndTime)

```

Output

```auto
2022-02-28 08:31:29.221000
2022-02-28 08:36:29.221000

```

I have to use without “miliseconds” part. How can I remove these part? I mean, it should be like **2022-02-28 08:31:29**

Thanks

---

<div class="post-metadata">

**Author:** ![Aditya\_Patil](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@Aditya\_Patil](https://forum.inductiveautomation.com/u/Aditya_Patil)\
**Post date:** [February 28, 2022, 8:51am UTC](https://forum.inductiveautomation.com/t/datetime-format-problem/56608/2 "2022-02-28T08:51:25Z")

</div>

> [@eren.uyanik](#):
>
> `%Y-%m-%d %H:%M:%S`

import datetime

pitchStartTime = datetime.datetime.utcnow()  
p\_time =pitchStartTime.strftime("%Y-%m-%d %H:%M:%S")  
print(p\_time)  
pitchEndTime = (pitchStartTime + datetime.timedelta(minutes=5))  
p\_end = pitchEndTime.strftime("%Y-%m-%d %H:%M:%S")  
print(p\_end)

results

> > >

2022-02-28 08:50:38  
2022-02-28 08:55:38

> > >

---

<div class="post-metadata">

**Author:** ![eren.uyanik](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/eren.uyanik/32/30923_2.png) [@eren.uyanik](https://forum.inductiveautomation.com/u/eren.uyanik)\
**Post date:** [February 28, 2022, 9:01am UTC](https://forum.inductiveautomation.com/t/datetime-format-problem/56608/3 "2022-02-28T09:01:58Z")

</div>

I couldn’t catch it because I did the conversion in the wrong place, thanks 🙂

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [February 28, 2022, 4:56pm UTC](https://forum.inductiveautomation.com/t/datetime-format-problem/56608/4 "2022-02-28T16:56:20Z")

</div>

I would recommend not using the python/jython Datetime class. I would instead use Ignition’s builtin `system.date.*` functions. In this case,

```auto
pitchStartTime = system.date.now()
pitchEndTime = system.date.addMinutes(pitchStartTime,5)
print system.date.format(pitchEndTime,'yyyy-MM-dd hh:mm:ss')

```

returns `2022-02-28 08:59:18`

If you go this way, the format string will use SimpleDateFormat structure as described here: [SimpleDateFormat (Java Platform SE 7 )](https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html)
