# SQL Cast Datetime

**URL:** <https://forum.inductiveautomation.com/t/sql-cast-datetime/7121>\
**Category:** Ignition\
**Created:** [August 22, 2013, 6:08pm UTC](https://forum.inductiveautomation.com/t/sql-cast-datetime/7121 "2013-08-22T18:08:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![AJBerera](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@AJBerera](https://forum.inductiveautomation.com/u/AJBerera)\
**Post date:** [August 22, 2013, 6:08pm UTC](https://forum.inductiveautomation.com/t/sql-cast-datetime/7121/1 "2013-08-22T18:08:40Z")

</div>

OK, so I’ve got a SQL Insert inside of a loop and I want ALL of the Inserts to use the same timestamp so I’ve concluded that I should  
use something like :

```auto
time = datetime.datetime.now()
```

outside the loop

and inside:

```auto
system.db.runUpdateQuery("UPDATE table SET count = 0, t_stamp = CAST('%s' AS datetime) WHERE type = '%i'"% (time, typeID))
```

I am not converting the datetime type correctly…

EDIT:  
I found my mistake  
I needed:

```auto
time = now.strftime('%Y-%m-%d %H:%M:%S')
```
