4 ms·
>> Watch out when using NOW() in your db. Would you be so kind as to elaborate on this? It was always my thought that NOW() was the more sensible approach as
by zer00eyz 3y ago
>> Watch out when using NOW() in your db.
Would you be so kind as to elaborate on this?
It was always my thought that NOW() was the more sensible approach as it would capture time in the execution order from a more centralized source (the db server). Where having the origin of a transaction setting at time would get me when, on the origin server the query was initiated.
- macintux 3y agoNot the person to whom you're replying, but I suspect the problem isn't that the database is using NOW(), but that your code being tested will be using an entirely different time.
- jweir 3y agoBingo. There is nothing wrong with using NOW(), in of itself, and it maybe the best thing to do. But it may lead to surprising results when say you have an application that has mocked out time for a specific time, but you get db results for the current time. It introduces another clock into your system. I have found most of the time we were using NOW() we could pass the time into the query and create a more understandable chain of code.
- theamk 3y agoYou mostly want to be consistent. For example if you do a job scheduler which uses NOW() to create job, but a local clock to execute them, then any clock difference between machines will be causing hard-to-debug problems.