TDateTimePicker delphi获取年份和月份
我有一个内置SQL的SP,它有两个参数,一个是年,另一个是月 在delphi中,我在一个框架上添加了一个TDateTimePicker,以便让用户选择月份和年份 如何从TDateTimePicker重试年/日的值 我试过TDateTimePicker delphi获取年份和月份,delphi,datetimepicker,Delphi,Datetimepicker,我有一个内置SQL的SP,它有两个参数,一个是年,另一个是月 在delphi中,我在一个框架上添加了一个TDateTimePicker,以便让用户选择月份和年份 如何从TDateTimePicker重试年/日的值 我试过DateTimePicker2.Date但这会给我一个格式为“xx/xx/xxxx”的日期 我想得到实际的年/月 差不多 int year ; year := DateTimePicker2.Date.Year; 有什么方法可以实现这一点吗?正如TLama所说,您可以像这样使
DateTimePicker2.Date代码>但这会给我一个格式为“xx/xx/xxxx”的日期
我想得到实际的年/月
差不多
int year ;
year := DateTimePicker2.Date.Year;
有什么方法可以实现这一点吗?正如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;
在DateUtils
您的代码将是:
year := YearOf(DateTimePicker1.Date);
month := MonthOf(DateTimePicker1.Date);
如果DateTimePicker1.Date
中的值为27/8/2015
然后年的值为2015,月的值为8。使用和功能。或者马上去拿。谢谢你,先生!我知道有函数可以执行此操作,但我找不到它们。你想回答@TLama?@Andy_D,不,对不起。我没有时间写一些关于衰老的童话:-)请随意发表一篇…否决选民,请说出你为什么否决这个问题。