Peter Kiers
asked on
Reverste date
Dear Experts,
I have a dataset with data on my form created the following way:
->a DBGrid1 on myform with property DataSource set to DataSource1.
->a DataSource1 with property DataSet set to ClientDataset1
->a ClientDataSet with property ProviderName set to XMLTransformProvider1.
and property Active to True.
->a XMLTransformProvider1 with the property FileName set to a xml-filename.
->and a DBNavigator with the propery DataSource set to DataSource1.
->and I have set the 3 columns:'dt','tm' and 'val' (dt=date,tm=time,and val=value)
as persistend fields in the DBGrid.
The date in the xml-file is: yy-mm-dd
and I would like to have it displayed backwords in the dbgrid: dd-mm-yy
I have allready these procedures:
function CustomStrToDate(DateString : string) : TDatetime;
var
dd, mm, yy : string;
begin
result := 0;
yy := copy(DateString,1, 4);
mm := copy(DateString,6, 2);
dd := copy(DateString,9, 2);
result := encodedate(strtoint(yy), strtoint(mm), strtoint(dd));
end;
(*------------------------ ---------- ---------- -------*)
procedure TMainForm.ClientDataSet1Ca lcFields(D ataSet: TDataSet);
const
Days : array[0..6] of string
= ('Zondag', 'Maandag', 'Dinsdag', 'Woensdag', 'Donderdag', 'Vrijdag', 'Zaterdag');
const
DoubleFormat: TFormatSettings = (DecimalSeparator: '.');
var
Str: string;
Value: Extended;
begin
clientdataset1.fieldbyname ('Da').ass tring := Days[DayOfTheWeek(CustomSt rToDate(cl ientdatase t1.fieldby name('Dt') .asstring) )-1];
Str:= StringReplace(ClientDataSe t1.FieldBy Name('Val' ).AsString , ',', '.', []);
if TryStrToFloat(Str, Value, DoubleFormat) then
begin
if Value < 4 then
ClientDataSet1.FieldByName ('St').AsS tring:= 'HYPO'
else if Value > 10 then
ClientDataSet1.FieldByName ('St').AsS tring:= 'HYPER'
else
ClientDataSet1.FieldByName ('St').AsS tring:= '';
end
else
ClientDataSet1.FieldByName ('St').AsS tring:= '';
end;
Who knows the anser how to reverse the date.
Peter
I have a dataset with data on my form created the following way:
->a DBGrid1 on myform with property DataSource set to DataSource1.
->a DataSource1 with property DataSet set to ClientDataset1
->a ClientDataSet with property ProviderName set to XMLTransformProvider1.
and property Active to True.
->a XMLTransformProvider1 with the property FileName set to a xml-filename.
->and a DBNavigator with the propery DataSource set to DataSource1.
->and I have set the 3 columns:'dt','tm' and 'val' (dt=date,tm=time,and val=value)
as persistend fields in the DBGrid.
The date in the xml-file is: yy-mm-dd
and I would like to have it displayed backwords in the dbgrid: dd-mm-yy
I have allready these procedures:
function CustomStrToDate(DateString
var
dd, mm, yy : string;
begin
result := 0;
yy := copy(DateString,1, 4);
mm := copy(DateString,6, 2);
dd := copy(DateString,9, 2);
result := encodedate(strtoint(yy), strtoint(mm), strtoint(dd));
end;
(*------------------------
procedure TMainForm.ClientDataSet1Ca
const
Days : array[0..6] of string
= ('Zondag', 'Maandag', 'Dinsdag', 'Woensdag', 'Donderdag', 'Vrijdag', 'Zaterdag');
const
DoubleFormat: TFormatSettings = (DecimalSeparator: '.');
var
Str: string;
Value: Extended;
begin
clientdataset1.fieldbyname
Str:= StringReplace(ClientDataSe
if TryStrToFloat(Str, Value, DoubleFormat) then
begin
if Value < 4 then
ClientDataSet1.FieldByName
else if Value > 10 then
ClientDataSet1.FieldByName
else
ClientDataSet1.FieldByName
end
else
ClientDataSet1.FieldByName
end;
Who knows the anser how to reverse the date.
Peter
ASKER
Could you please be more specific or guide me step by step.
P.
P.
you need a query to reverse the sorting
DBGrid doesn't natively support sorting on the grid itself
you need to sort the data
or using a other dbgrid like TCRDBGrid from DevArt
don't you have a grid in the jedi components ?
that should allow for sorting
DBGrid doesn't natively support sorting on the grid itself
you need to sort the data
or using a other dbgrid like TCRDBGrid from DevArt
don't you have a grid in the jedi components ?
that should allow for sorting
ow, you only want the date in a other format in the column ?
add a calculated field of type string
ClientDataSet1.FieldByName ('datecolu mn').AsStr ing:= FormatDateTime('dd-mm-yy', clientdataset1.fieldbyname ('Da').asD ateTime);
add a calculated field of type string
ClientDataSet1.FieldByName
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ClientDataSet1.FieldByName ('Dtr').As String:= FormatDateTime('dd-mm-yy', clientdataset1.fieldbyname ('Dt').asD ateTime);
error: 2010-06-19 is not a valid date and time
P
error: 2010-06-19 is not a valid date and time
P
ASKER
Aflarin came with the right solution it works great.
Thanks.
Peter Kiers
Thanks.
Peter Kiers
my solution is correct providing you saved the data as a datetime and not as a string in your database
otherwise you should actually accept cyberkiwi's solution
because it is not a date conversion but a string to string conversion
allways try to store data in a non converted way in the database
if you want to see 2 decimals on the screen and you have 6 decimals in your value
you will store 6 decimals in your db and not 2
you will keep getting errors otherwise
keep in mind that your application will only work in your own country
or with your country settings
if somebody else has different country settings for the dates, your app will not work
otherwise you should actually accept cyberkiwi's solution
because it is not a date conversion but a string to string conversion
allways try to store data in a non converted way in the database
if you want to see 2 decimals on the screen and you have 6 decimals in your value
you will store 6 decimals in your db and not 2
you will keep getting errors otherwise
keep in mind that your application will only work in your own country
or with your country settings
if somebody else has different country settings for the dates, your app will not work
ClientDataSet1.FieldByName
And add that persistent field to the Grid