Date and Datetime format in TWebClientDataset.GetPendingUpdates

Hi, when using Dataset.GetPendingUpdates to extract the JSON, how can I format the TDateFields date to match my requirements? Currently, it is always exported in the format 'yyyy-mm-ddT00:00:00.000Z', but I only need the 'yyyy-mm-dd' part. The field is connected to a TWebDBDateTimePicker of kind dtkDate.
There is a DefaultFormat to set? Or any hint for solve?
Thanks

The default format is the ISO 8601 format which is the JSON standard format.
In a JSON dataset, the ftDate, ftTime and ftDateTime fields are respectively represented by TJSONDateField, TJSONTimeField and TJSONDateTimeField.
These classes have properties TJSONDateField.DateFormat, TJSONTImeField.TimeFormat and TJSONDateTimeField.DateTimeFormat with which the default format can be overridden.

Hi Bruno,
Thanks.
Can you write a quick code example with uses for setting generally those in WebCore?
I need the correct format that match deserialize that Json in Xdata service, with use TxdataJsonServerDeserializer (and relative TxdataJsonServerSerialize in another service).
Thanks a lot!

@Monterisi_Stefano can you please elaborate a little bit more about what you are trying to accomplish, and when, exactly? It's not clear to me the relation between TWebDBDataTimePicker and TXDataJsonServerDeserializer. There is a very long path between one and another.

Of course :-)
I use TwebClientDataset.Get PendingUpdates to extract the Json of the changes made in the dataset, to be sent via an XDATA service that takes care of doing the CRUD on the server with Aurelius classes.
This service is generic, so I pass a Json array that contains both the name of the class (Invoice for example, row by row) and the content of the modified or inserted records.
In this way, on the server side, I receive a json containing the crud of several tables in a single call.
A function creates the necessary Aurelius objects and fills them through
TxdataJsonServerDeserializer, before performing the validation and saving (TInvoice.Save, TInvoice.update, TInvoice.Remove).
In short A generic service that allows the crud for several tables in a single transaction and a single call, and that works well.
The problem is that in the Json created by Tweb ClientDataset.Get PendingUpdates, fields of type Tdate are exported in the format 'yyyy-mm-ddT00:00:00.000Z'
and not 'yyyy-mm-dd'.
This format in the Tdate field is NOT accepted, server side, by TxdataJsonServerDeserializer that raises an exception.

Example of server side:

function ApplyUpdateGen(AApplyUPD: Tlist): String;
var
tmpApplyUPD: TApplyUPD;
Deserializer: TXdataJsonServerDeserializer;
tmpValue: string;
I: integer;
tmptable: string;
tmpoperaz: integer;
tmpObject: Tobject;
tmpManager: TObjectManager;
transaction: IDBTransaction;
ValidationResult: IManagerValidationResult;
Error: IValidationError;
begin
result:='KO';
tmpManager:= TXDataOperationContext.Current.GetManager;
Deserializer := TXdataJsonServerDeserializer.Create(TXDataAureliusModel.default,nil);
transaction:=tmpmanager.Connection.BeginTransaction;
try
for I := 0 to AApplyUPD.Count -1 do
begin
tmpApplyUPD:= AApplyUPD[i];
tmptable:= tmpApplyUPD.D1;
tmpOperaz:= tmpApplyUPD.D2;
tmpValue:=tmpApplyUPD.D3.ToString;
tmpObject:=DeserializzaObject(tmpManager, Deserializer,tmptable,tmpValue);
if tmpObject <> nil then
begin
tmpManager.Validate(tmpObject);
if tmpOperaz=1 then
begin
tmpManager.Save(tmpObject);
result:='OK INS';
end;
if tmpOperaz=2 then
begin
tmpManager.Update(tmpObject);
result:='OK UPD';
end;
if tmpOperaz=3 then
begin
tmpManager.Update(tmpObject);
tmpManager.Remove(tmpObject);
result:='OK DEL';
end;
end;
end;
//
if tmpmanager.HasChanges then
tmpmanager.Flush; // save updates to DB
//
transaction.Commit;
//
except
.....
......

Now it's clear :slight_smile:

Try to use this approach:

and here is a more detailed explanation about the options:

Hi,
Ok, I will try tomorrow.
But the TWebClientDataset.GetPendingUpdates must convert TDateFields date into 'yyyy-mm-dd' format, not 'yyyy-mm-ddT00:00:00.000Z'.The bug remain in Tms WebCore, a correction is necessary.
Thanks a lot.

I'm sorry but I do not think it should.
Multiple sources say all the same, the recommended representation for a date/datetime/time in JSON is to use the ISO8601 format. JavaScript itself converts a Date type with toJSON to ISO 8601.

JSON (JavaScript Object Notation) doesn't have a built-in date type, so dates are typically represented as strings, following a standardized format.

Recommended Format: ISO 8601

The most common and widely accepted way to represent a date in JSON is:

{
  "date": "2025-06-15T14:30:00Z"
}

Or see for example:

https://stackoverflow.com/questions/10286204/what-is-the-right-json-date-format

etc..

This is how the pas2js team developed the RTL TJSONDataSet (of which TWebClientDataSet descends) to use ISO8601.

If you do not include the time yourself in the JSON representation, that is what it is , you do not include it. But if you ask the dataset to generate the JSON representation, it will use ISO
8601.

I answered this already in my first reply to this post.

Well,
given that I don't want to waste your time, but that I have problems that often block my work, tell me how I can "digest" and save this date, coming from TWebClientdataset.GetPendingUpdates: "f24_datanascita":"1972-12-21:T00:00:00.000Z"
in Xdata, where the field in Aurelius Class is this:
[Column('f24_datanascita', )]
Ff24_datanascita: TDate;

When the service call deserialize (with TXdataJsonServerDeserializer), in
Xdata.Json.Converter I have an exception in
Function TXDataJsonObjectConverter.GetConverter(....)
at row Result:= Converters.Get(PropInfo.RttiInfo.RealType.Handle).

I also set DefaultTimeZoneMode: TTimeZoneMode.Ignore (Bcl.Utils).
But the exception in Xdata is always present.
Note: If I pass a date formatted "yyyy-mm-dd" everything works.

Hi,
Is there any confirmation for this incompatibility between TwebClientDataset's Data format and XDATA deserialization?
Any solution?
I have a couple of projects stuck on small anomalies.
Tms WebCore is really useful and powerful for my needs, but it gets stuck for a long time for small things to fix, given its young age.
Thanks in advance

We will manage to release a XData update that will accept TDate values with the time part, at least if the time part is only zeros. Such time part will be ignored then.

Perfect,
thanks