我有一个用SQL构建的SP,它有两个param,一个是年份,另一个是月份。
在delphi中,我在一个框架中添加了一个TDateTimePicker,以便让用户选择月份和年份。
如何从TDateTimePicker中检索年度/日值?
我尝试过DateTimePicker2.Date;,但这给了我一个格式为"xx/xx/xxxx“的日期
我想得到实际的年份/月
就像这样
int year ;
year := DateTimePicker2.Date.Year;我有办法做到这一点吗?
发布于 2014-07-14 14:14:51
正如TLama所说,您可以像这样使用DecodeDate函数:-
Var
lDay,
lMonth,
lYear : Word;
Begin
DecodeDate(DateTimePicker2.Date, lDay, lMonth, lYear);
MyStoredProc.Params[0].AsInteger := lDay;
MyStoredProc.Params[1].AsInteger := lMonth;
MyStoredProc.Execute;
End;发布于 2015-09-01 10:03:44
在YearOf()和MonthOf()中使用DateUtils函数
你的代码是:
year := YearOf(DateTimePicker1.Date);
month := MonthOf(DateTimePicker1.Date);如果DateTimePicker1.Date中的值是27/8/2015,那么年份的值是2015年,月份是8。
https://stackoverflow.com/questions/24737327
复制相似问题