Recent

Author Topic: [SOLVED] Time Format  (Read 426 times)

pjtuloup

  • New Member
  • *
  • Posts: 45
[SOLVED] Time Format
« on: October 05, 2024, 05:45:15 pm »
Hi,

I need to save the time in a field of a database table, this field being in TIME format.
But DataModule1.SQLQuery1.ParamByName('Chp4t').AsTime := Time; leaves the time in hh:mm:ss.xxxx format which is obviously refused by the database... How to reformat the time in hh:mm:ss?

It's crazy but I haven't found anything usable (or understandable by me) on this problem
« Last Edit: October 06, 2024, 04:26:10 pm by pjtuloup »

paweld

  • Hero Member
  • *****
  • Posts: 1268
Re: Time Format
« Reply #1 on: October 05, 2024, 06:21:50 pm »
If the RDBMS will accept time as string, you can try:
Code: Pascal  [Select][+][-]
  1. DataModule1.SQLQuery1.ParamByName('Chp4t').AsString := FormatDateTime('hh:nn:ss', Time);
Best regards / Pozdrawiam
paweld

pjtuloup

  • New Member
  • *
  • Posts: 45
Re: [SOLVED] Time Format
« Reply #2 on: October 06, 2024, 04:27:22 pm »
Thanks Paweld !

But it's a little bit strange to have to use this (I think)

paweld

  • Hero Member
  • *****
  • Posts: 1268
Re: [SOLVED] Time Format
« Reply #3 on: October 06, 2024, 06:27:40 pm »
I also find it strange. If the column is defined as "TIME" (in a db table), then passing the parameter as time should work without any problem.
Best regards / Pozdrawiam
paweld

CharlyTango

  • Jr. Member
  • **
  • Posts: 90
Re: [SOLVED] Time Format
« Reply #4 on: October 08, 2024, 07:38:55 pm »
But DataModule1.SQLQuery1.ParamByName('Chp4t').AsTime := Time; leaves the time in hh:mm:ss.xxxx format which is obviously refused by the database

if I don't need the clients time (lets see for starting and stopping something) but I need the DateTime or Timestamp for (e.g logging purposes - Time_created or Time_Updated) i leave the job to the SQL-Server.
You can create the table in a manner that creation dates were inserted as well as update datetimes. Sometimes special triggers will do the job.

In these cases, there are no more problems with date fields

Lazarus stable, Win32/64

 

TinyPortal © 2005-2018