CiucaS
CiucaS

Reputation: 2128

TDateTimePicker delphi get year and month

I have a SP built in SQL that has 2 param, one is year and the other one is month.

In delphi I added a TDateTimePicker on a frame in order to let the user pick the month and the year.

How do I retrie the values of the Year/Day from TDateTimePicker?

I've tried DateTimePicker2.Date; but this gives me a date in format "xx/xx/xxxx"

I want to get the actual Year/month

something like

int year ;
year :=  DateTimePicker2.Date.Year;

Is there any way I can achieve this ?

Upvotes: 3

Views: 9953

Answers (2)

Binitta Mary
Binitta Mary

Reputation: 134

Use YearOf() and MonthOf() functions in DateUtils

You code will be:

year := YearOf(DateTimePicker1.Date);
month := MonthOf(DateTimePicker1.Date);

If the value in the DateTimePicker1.Date is 27/8/2015 then the value of year is 2015 and month is 8.

Upvotes: 4

Andy_D
Andy_D

Reputation: 2350

As TLama said you can use the DecodeDate function like this :-

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;

Upvotes: 5

Related Questions