Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 12-02-2002, 03:28 PM
Deep Deep is offline
Senior Member
 
Join Date: Feb 2001
Posts: 158
Default Getting the Year, Month and the Day (Date)

Hi,

I need to get the current year, current month and all the days in the current month. I need to put the year in one variable, the month in another variable and the days in an array that keeps thack of all the days.

Please help!

Deep S
Reply With Quote
  #2  
Old 12-02-2002, 06:30 PM
Dezful Dezful is offline
Junior Member
 
Join Date: Jul 2002
Posts: 13
Default RE: Getting the Year, Month and the Day (Date)

Hi ,

It is very easy ,

See:

Var
year,month,Day : Word;
Present: TDateTime;

begin
Present:= Now;
DecodeDate(Present, Year, Month, Day);

End;


Now You can use from it.

Your Friend
Ali Reza




Ali Reza
Reply With Quote
  #3  
Old 12-02-2002, 06:31 PM
GoodFun GoodFun is offline
Senior Member
 
Join Date: Jan 2001
Posts: 2,645
Default RE: Getting the Year, Month and the Day (Date)

try this... I suggest though to use a StringList for all the days of the month... makes it easier to for example add objects attached to each day.

var CurYear: String;
var CurMonth: String;
var DaysInMonth: TStringList;
var LastDayOfMonth: TDateTime;
var FirstDayOfMonth: TDateTime;
var Year, Month, Day: Word;
var i, NbrOfDays: Integer;

DaysInMonth := TStringList.Create; // don't forget to free it
// when you are done with it

CurYear := FormatDateTime('yyyy', Now);
CurMonth := FormatDateTime('mm', Now);

DecodeDate(Now, Year, Month, Day);

FirstDayOfMonth := EncodeDate(Year, Month, 1);
LastDayOfMonth := IncMonth(FirstDayOfMonth, 1);

NbrOfDays := LastDayOfMonth - FirstDayOfMonth;

for i := 1 to NbrOfDays do
begin
DaysInMonth.Add(IntToStr(i));
end;

something like this... I'm sure there are easier solutions but it really depends a bit on what you're trying to do...

Hope this helps,

Marcel

Please click on Accept if this helped...
Reply With Quote
  #4  
Old 12-03-2002, 04:12 AM
Deep Deep is offline
Senior Member
 
Join Date: Feb 2001
Posts: 158
Default RE: Getting the Year, Month and the Day (Date)

Just one problem, I keep getting an error message that seas: "Incompatible types: 'Integer' and 'Extended'"

The read error line is placed on the:
NbrOfDays := LastDayOfMonth - FirstDayOfMonth;
line.

Deep S
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 12:48 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.