Insert minute on data base

hello everyone

I have a script for Insert information on database I used a TAG Events on Value Changed.

I have a TAG called TimeDiff that takes me the minutes.

in my insert I call this tag so that it gives me the minutes it has to save them in my database

but it only saves me 00:00:00

I do not save the minutes it takes

image

Your column configuration at DB seems to have the wrong type. It looks like you have configured it as datetime but you’re giving a unicode. When you do system.date.format(datetime,‘HH:mm:ss’) you’re only extracting the time part as string but not the date.
Reconfigure your db column to be Time() or LongBlob() datatype.

My column is Type TIME

image

What happens if you don’t do the format, and send a date type object instead of a string?

I’m assuming that you’re print statements reveal that timeDiff is not zero.

Yes is for reveal that timeDiff is not zero and when I don’t do the format is similar, insert just 00:00:00

Have you tried manually executing the query for example in SSMS/Workbench/etc.? Or even just in Ignition’s query tool

insert it correctly

image

Clasping at straws here, but what if you cast the original date.format to a string?

Contador = system.date.format(Contador, 'HH:mm:ss')
Contador = str(Contador)

What is the print Contador line printing out?

keep saving 00:00:00

My guess is that the prepUpdate function isn’t handling the time datatype properly… @PGriffith?

Are you actually getting a non-zero print out for the timeDiff variable in line 10?

He showed this in the OP:
image

Yeah, but that is an expression tag that could be changing (plus he is reading the MemTimeDiff tag not the TimeDiff tag which is confusing me). Would also double check the tag hierarchy here as the relative tagpath [.]../MemTimeDiff indicates the script should be on a tag in a folder one level down from the MemTimeDiff tag (if I remember my .'s correctly).

You’re right… I must be tired :confused:

1 Like

@antonio.sanchez I see you mentioned earlier that you are getting a non-zero value for your timeDiff variable, but I didn’t actually see the result of the print, just a screenshot of your tags. Can you post the actual results from your print statements here?

Can you print “Contador” in line 15 with:

system.util.getLogger("TimeContador").info(str(Contador))

And trigger a value change, Go to Gateway web page>Status>Logs and see the value

sorry for the delay,
I Have the next

Is that what the logger logged or…? (you updated the screenshot) If so, you have your answer, you’re passing in 00:00:00 into the insert

Are you sure this shouldn’t be TimeDiff instead of MemTimeDiff?

What is the value of the MemTimeDiff tag?
This value must be 0 at the moment

1 Like

Also, where is the tag you have this script defined on in relation to your MemTimeDiff tag? Is it in the same folder or a different sub folder?

Because it does appear to be reading and isn't null, I'd assume that the tag link is correct