Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I want to extract the month from a datetime (the present month). I use the
Delphi
DecodeDate(date,year,month,day);
edit1.Text := datetimetostr(month);

but it gives me as a result the full date of 2/1/1900, it is weird I am using Delphi 7. Any help?

Thank you
Kyriakos
Posted

Based on this information[^] it's doing what you asked. Try printing just the month value.
 
Share this answer
 
You're almost there! You've already retrieve the month, but there is something wrong with showing the result.

A correct example would be
Delphi
procedure ShowMonth;
var
  Day, Year, Month: Word;
  Today: TDateTime;
begin
  Today:= Now;
  DecodeDate(Today, Year, Month, Day);
  ShowMessage(IntToStr(Month));//Month here is 1, 2, ..., 12
end;


The problem is from the call to DateTimeToStr which takes a TDateTime which is just a type of Double which means number of days since Dec 30 1899.

So, the call to DateTimeToStr will just give you some day around 1900, depending on the value of Month you have got.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900