德尔福ADO:日期时间到字符串的转换 [英] Delphi & ADO: datetime to string conversion
问题描述
我使用Delphi 2006和ADO连接到MS Access数据库。我检索的某些字段是日期字段(在Access中格式为中级日期,即2010年4月20日),但是我必须将它们检索为字符串:
I use Delphi 2006 and ADO to connect to a MS Access database. Some of the fields I retrieve are Date fields (in Access formatted as "Medium Date" i.e. 20-Apr-2010) however I have to retrieve them as Strings:
FValue:=FAccessADOQuery.Fields.FieldByName(FIELD_NAME).AsString;
,然后将字段格式设置为:4/20/2010。
and then the fields are formatted as follows: 4/20/2010.
我的问题是:这种格式何时发生,如何自定义?是ADO设置(在那里找不到任何内容)还是OS(我在美国语言环境中使用Win XP ENG)?也许是德尔菲?
My question is: when does this formatting take place and how can I customize it? Is it ADO settings (could not find anything there) or the OS (I use Win XP ENG with US locale)? Or maybe it's Delphi?
谢谢!
Lou
Thanks! Lou
推荐答案
ShortDateFormat
和 LongTimeFormat
变量用于将TDateTimeField格式化为字符串。
the ShortDateFormat
and LongTimeFormat
variables are used to format an TDateTimeField to string.
您可以更改这些变量的值或尝试类似的其他操作:
you can change the value of theses variables or try something different like this :
Dt :TDateTime;
Ds :String;
begin
//FAccessADOQuery.Fields.FieldByName(FIELD_NAME).AsString
Dt:=FAccessADOQuery.Fields.FieldByName(FIELD_NAME).AsDateTime;
Ds:=FormatDateTime('dd-mmm-yyyy',dt);
end;
这篇关于德尔福ADO:日期时间到字符串的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!