#1 2014-03-27 14:11:56

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

Get TDateTime from TCreateTime and TModTime with TSQLTableJSON

I need use a query to get data from database as TSQLTableJSON.
TSQLTableJSON of 2 fields as TCreateTime and TModTime (create e edit date of record);
How can I get TDateTime from these 2 fields?

Offline

#2 2014-03-27 23:10:48

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

Re: Get TDateTime from TCreateTime and TModTime with TSQLTableJSON

I have try this:

TimeLogToDateTime(GetInt64(Table.Get(x, y)));

but with last versions of framework I get an error: "Invalid argument to time encode".

The some code in the past it's ok.

Any idea?

Offline

#3 2014-03-28 17:36:01

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Get TDateTime from TCreateTime and TModTime with TSQLTableJSON

Why not use just use the function TSQLTable.GetAsDateTime() ?

If you get an error here, this may be because of wrong value in the field, i.e. not a true TTimeLog value.

Offline

#4 2014-03-29 12:49:52

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

Re: Get TDateTime from TCreateTime and TModTime with TSQLTableJSON

I just have try TSQLTable.GetAsDateTime() but I get always "30/12/1899".
I have check on my database: all RecordCreated and RecordModified have 0 as value.
I don't have understand the error, I have a TSQLRecord class like this:

  TSQLProjects = class(TSQLRecord)
  private
    fRecordCreated: TCreateTime;
    fRecordModified: TModTime;
    ...
  published
    property RecordCreated: TCreateTime read fRecordCreated write fRecordCreated;
    property RecordModified: TModTime read fRecordModified write fRecordModified;
    ...
  end;

I think these fields (RecordCreated and RecordModified) are handle by framework when I create, add or update a record, right?
I don't edit them by code.

Any ideas?

Offline

#5 2014-03-29 16:06:26

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Get TDateTime from TCreateTime and TModTime with TSQLTableJSON

Are you sure you are using the Add/Update CRUD methods of the framework?
If you use direct SQL, those fields won't be filled.
Those TCreateTime and TModTime are ORM-related methods.

Those fields are checked during regression tests, even within the performance tests, so I wonder why you get 0...

Offline

#6 2014-03-29 17:37:00

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

Re: Get TDateTime from TCreateTime and TModTime with TSQLTableJSON

I will make some test.
I'm working on my old project and only today I have update it with last version of framework after many time. I hope is not change something on framework from my last software compile.

Offline

#7 2014-03-29 17:45:24

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

Re: Get TDateTime from TCreateTime and TModTime with TSQLTableJSON

OK. I have try to open my database with your SynDB Explorer (in the past I have open it with a 3rd editor) and both RecordCreated and RecordModified are not 0.
These are some value:

135039350706
135123213736

Anyway I get "30/12/1899" when I use TSQLTable.GetAsDateTime().

Offline

#8 2014-03-30 08:37:35

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

Re: Get TDateTime from TCreateTime and TModTime with TSQLTableJSON

OK I make some test with my DB.

1. I have use GetString to retrive text value of fields:
135131870949
135128992597
135115886182

2. I have only change GetString to GetAsDateTime and I get these:
135131870949 -> 30/12/1899
135128992597 -> 30/12/1899
135115886182 -> 30/12/1899

the fields have different value but the datatime is the same.

Offline

#9 2014-03-30 13:22:13

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Get TDateTime from TCreateTime and TModTime with TSQLTableJSON

When I execute TimeLogToDateTime(135131870949) it returns 41578.477512, which is correct.

I'm not able to reproduce your problem.
Please check your code.

Are you sure the field is clearly identified as sftModTime or sftCreateTime in the TSQLTable?
You need to set it manually, via TSQLTable.SetFieldType('FieldName',sftModTime), otherwise it will not use conversion from TTimeLog value.

Offline

Board footer

Powered by FluxBB