function DateTimeToStr(DateTime: TDateTime): string;【函数声名的形式】
Description【描述,详细的说明】
DateTimeToString converts the TDateTime value given by DateTime using the format given by the ShortDateFormat global variable, followed by the time using the format given by the LongTimeFormat global variable. The time is not displayed if the fractional part of the DateTime value is zero. 【DateTimeToStr转换通过DateTime参数传入的TDateTime类型的值为字符串,根据ShortDateFormat全局变量所给定的日期格式,遵循LongTimeFormat所给定的时间格式。如果DateTime的小数部分为零的话返回的字符串中将没有时间部分】
To change how the string is formatted, change ShortDateFormat and LongTimeFormat global date time formatting variables.【要改变字符串的格式,可以通过改变ShortDateFormat和LongTimeFormat全局日期时间格式变量来实现】
三、和数据库中的日期字段 有人询问怎样在SQL中设定Date/DateTime类型的查询值,这和数据库本身有关。不同的数据库对日期类型的字段一般都有对应的函数和格式,不过应该都支持ANSI标准——谁叫数据库厂商都是美国的。比如,我在Oracle8中要查询日期型字段我一般使用【Select * From LoginTable Where LoginTime >= To_Date('2003.03.01 00:00:00','yyyy.mm.dd hh24:mi:ss')】,MSSQLServer2000中文版的写法是【Select * From LoginTable Where LoginTime >= '2003-03-01 00:00:00'】,SQLServer的联机帮助中讲得比较详细,而且用起来似乎也比较方便,不过Oracle可以自己设定日期格式。 说句题外话,查询的时候,很多人为了方便往往把日期型的字段用函数转换成字符串,然后和字符串式的日期来进行比较,例如:【Select * From LoginTable Where To_Char(LoginTime,'yyyy.mm.dd hh24:mi:ss') >= '2003.03.01 00:00:00'】,这样的写法语法上没有问题,但是性能上存在很大的隐患。因为,数据库执行这样的查询是要对每一条记录的loginTime字段进行计算然后再比较,如果记录数多,会很慢。