# Best practice question - writing current timestamp to SQL database

**URL:** <https://forum.inductiveautomation.com/t/best-practice-question-writing-current-timestamp-to-sql-database/90829>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [May 23, 2024, 7:54pm UTC](https://forum.inductiveautomation.com/t/best-practice-question-writing-current-timestamp-to-sql-database/90829 "2024-05-23T19:54:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bushmatic](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bushmatic/32/87014_2.png) [@Bushmatic](https://forum.inductiveautomation.com/u/Bushmatic)\
**Post date:** [May 23, 2024, 7:54pm UTC](https://forum.inductiveautomation.com/t/best-practice-question-writing-current-timestamp-to-sql-database/90829/1 "2024-05-23T19:54:00Z")

</div>

Wondering if there is any significant distinction between the following methods of recording a timestamp while creating a database record:

- Using Ignition's `system.date.now()` function, then inserting that value
- Using the database's `CURRENT_TIMESTAMP` function (assuming Microsoft SQL Server)

Example of first one:

```python
partNum = '555AB'
now = system.date.now()
query = """INSERT INTO Orders
(PartNum,InsertedOn) VALUES(?,?)"""
args = [partNum,now]
system.db.runPrepUpdate(query,args,'MyDbConnection')

```

Example of second one:

```python
partNum = '555AB'
query = """INSERT INTO Orders
(PartNum,InsertedOn) VALUES(?,CURRENT_TIMESTAMP)"""
args = [partNum]
system.db.runPrepUpdate(query,args,'MyDbConnection')

```

Is it even worth splitting hairs over?

---

<div class="post-metadata">

**Author:** ![Noah\_Casey](https://avatars.discourse-cdn.com/v4/letter/n/e480ec/32.png) [@Noah\_Casey](https://forum.inductiveautomation.com/u/Noah_Casey)\
**Post date:** [May 23, 2024, 8:03pm UTC](https://forum.inductiveautomation.com/t/best-practice-question-writing-current-timestamp-to-sql-database/90829/2 "2024-05-23T20:03:50Z")

</div>

I usually just let the db do the creation date.  
I would personally go with option two.

I would also recommend instead of writing raw queries create all your queries inside of named queries. It's a better practice and it will help you/anyone else behind you who may need to edit this application down the road. I've seen many projects where I have to dig and dig to find out that the queries are all raw queries while named queries you know where they are and what they are.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 23, 2024, 8:04pm UTC](https://forum.inductiveautomation.com/t/best-practice-question-writing-current-timestamp-to-sql-database/90829/3 "2024-05-23T20:04:33Z")

</div>

`CURRENT_TIMESTAMP` is from the database machine's clock. `system.date.now()` is from the Ignition machine's clock. Which one is right for your application?
