Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to Get the dates of the first and last day of the month of a given date Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
21-May-03
Category
Algorithm
Language
Delphi 3.x
Views
86
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Ernesto De Spirito

How can I get the dates of the first and last day of the month of a given date?

Answer:

FDOM and LDOM 

FDOM returns the date that corresponds to the first day of the same month as the 
date passed as parameter, while LDOM returns the date that corresponds to the last 
day of the month (subtracting 1 from the date that corresponds to the first day of 
the next month). 

1   function FDOM(Date: TDateTime): TDateTime;
2   var
3     Year, Month, Day: Word;
4   begin
5     DecodeDate(Date, Year, Month, Day);
6     Result := EncodeDate(Year, Month, 1);
7   end;
8   
9   function LDOM(Date: TDateTime): TDateTime;
10  var
11    Year, Month, Day: Word;
12  begin
13    DecodeDate(Date, Year, Month, Day);
14    if Month < 12 then
15      inc(Month)
16    else
17    begin
18      Month := 1;
19      inc(Year)
20    end;
21    Result := EncodeDate(Year, Month, 1) - 1;
22  end;
23  
24  //Sample call 
25  
26  procedure TForm1.Button1Click(Sender: TObject);
27  begin
28    ShowMessage(DateToStr(FDOM(Now)));
29    ShowMessage(DateToStr(LDOM(Now)));
30  end;


Copyright (c) 2001 Ernesto De Spiritomailto:edspirito@latiumsoftware.com
Visit: http://www.latiumsoftware.com/delphi-newsletter.php

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC