Recent

Author Topic: Stupid question: now/current_timestamp value  (Read 345 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 1913
    • Lazarus and Free Pascal italian community
Stupid question: now/current_timestamp value
« on: August 22, 2019, 11:31:55 am »
 Impara la pronuncia

Hi guys, I have a very trivial question about valuing a date in a database field. I work a lot with queries and know that with firebird when I want to set the date to the current date I just need to use the current_timestamp but for a project I have to use the process

MyQuery.Edit;
MyQuery.FieldByName('myfield').AsDateTime  := now;
MyQuery.Post;

Only that now populates the value with the date of the client and not of the server. How can I solve the problem?

Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

rvk

  • Hero Member
  • *****
  • Posts: 3798
Re: Stupid question: now/current_timestamp value
« Reply #1 on: August 22, 2019, 12:57:30 pm »
... but for a project I have to use the process
...
Only that now populates the value with the date of the client and not of the server. How can I solve the problem?
If you really need to use that exact process, you can't use current_timestamp or 'NOW'.

You have two options.
Change the INSERT to use current_timestamp or 'NOW'.
Or retrieve current_timestamp with a separate SQL-statement from the server and fill it in with the AsDataTime.

Code: SQL  [Select]
  1. SELECT CURRENT_TIMESTAMP FROM rdb$database


Only that now populates the value with the date of the client and not of the server. How can I solve the problem?
Is the date of the client so much different from that of the server ????

xinyiman

  • Hero Member
  • *****
  • Posts: 1913
    • Lazarus and Free Pascal italian community
Re: Stupid question: now/current_timestamp value
« Reply #2 on: August 22, 2019, 01:40:40 pm »
I figured it was the only solution.
Is the date of the client so much different from that of the server ????
In theory, no, but it can happen.
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

valdir.marcos

  • Hero Member
  • *****
  • Posts: 790
Re: Stupid question: now/current_timestamp value
« Reply #3 on: August 22, 2019, 06:08:17 pm »
Hi guys, I have a very trivial question about valuing a date in a database field. I work a lot with queries and know that with firebird when I want to set the date to the current date I just need to use the current_timestamp but for a project I have to use the process

MyQuery.Edit;
MyQuery.FieldByName('myfield').AsDateTime  := now;
MyQuery.Post;

Only that now populates the value with the date of the client and not of the server. How can I solve the problem?
As a matter of fact, this is a problem for a sysadmin and not for software developers...
https://en.wikipedia.org/wiki/Network_Time_Protocol
https://www.ntppool.org/

Just consider as a silly example that your sever is in Uruguay and you have clients in England and Japan.
You will be in trouble if you record local time instead of server centralized time.

You have two options.
Change the INSERT to use current_timestamp or 'NOW'.
Or retrieve current_timestamp with a separate SQL-statement from the server and fill it in with the AsDataTime.
+1