Advertisement

01.22.2008 at 04:58AM PST, ID: 23100922
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Date matching time period ...

Tags: Delphi / Pascal
Hi Experts,

I think i have a bit of a tricky situation here.

I have a client that requires some General Ledger Tools written and they have some very specific criteria.

The criteria is:

    (1) All dates entered into the ledger as a journal entry must be done on the last friday of the month.
    (2) Months have to correspond to a time period of the fiscal year. Ie: Australia is July - June = 1 to 12.

Example:

User Inputs:

Date                  Journal ID         Debit        Credit        Detail             Period
28/12/2008           1111             10.00        0.00          AccPayable        6                  Correct Entry
31/12/2008           1112               9.95        0.00          AccRecieve         6                  Wrong Entry

Lets say for this example the 28/12/2008 was a friday the entry should post to the database. If not it should be trapped and the error rasied.

I guess what i am looking for is a routine that i can pass a date and a period and return if it is correct, or put in a date and it returns the period for that date.

I have looked at a few date routines and i pretty much couldnt find what i was looking for.

Also keep in mind that some periods in a month may have 5 weeks not 4.

Regards,





Trevor
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: trevsoft
Solution Provided By: rllibby
Participating Experts: 3
Solution Grade: A
Views: 0
Translate:
Loading Advertisement...
01.22.2008 at 05:48AM PST, ID: 20714091

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.22.2008 at 05:54AM PST, ID: 20714133

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.22.2008 at 07:15AM PST, ID: 20714927

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.23.2008 at 03:04AM PST, ID: 20722336

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.05.2008 at 03:04PM PDT, ID: 21289836

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.11.2008 at 12:32PM PDT, ID: 21337437

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.11.2008 at 01:07PM PDT, ID: 21337766

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.16.2008 at 06:58PM PDT, ID: 21373585

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.18.2008 at 12:43AM PDT, ID: 21591864

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.24.2008 at 07:27PM PDT, ID: 21641048

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • Automotive
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Displays / Monitors
  • Handhelds / PDAs
  • Components
  • Peripherals
  • Laptops/Notebooks
  • Servers
  • Misc
  • Apple
  • Embedded Hardware
  • Networking Hardware
  • Storage
  • Desktops
  • New Users
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMware
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Virtualization
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • Web Computing
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Consulting
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMware
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Automation
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Web Services
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Web Computing
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Lounge
  • Business Travel
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
  • Automotive
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
01.22.2008 at 05:48AM PST, ID: 20714091
 
01.22.2008 at 05:54AM PST, ID: 20714133
 
01.22.2008 at 07:15AM PST, ID: 20714927

Rank: Genius

Below is code that should provide the functionality that you need; handles fiscal month <-> calendar month mapping, as well as determining the last friday of any month. You only need to set the FiscalYearStart var (1-12) to specify when the fiscal years starts, the rest of the functions will then make use of this.

Let me know if there are questions / problems
Russell

// Example usage
  // Fiscal year starts in July (July is first fiscal month)
  FiscalYearStart:=7;

  // Get the posting date for the 6th fiscal month (December)
  ShowMessage(DateToStr(GetPostingDate(6)));

  // Check that a given posting date is correct for the period that it falls in
  if IsValidPostingDate(StrToDate('3/28/2008')) then
     ShowMessage('Valid')
  else
     ShowMessage('Invalid');

  if IsValidPostingDate(StrToDate('2/21/2008')) then
     ShowMessage('Valid')
  else
     ShowMessage('Invalid');

-----------

unit GL_Example;
////////////////////////////////////////////////////////////////////////////////
//
//   Unit        :  GL_Example
//   Author      :  rllibby
//   Date        :  01.22.2008
//   Description :  Functions to check that a given date is correct for the
//                  posting period, as well as return the posting date for
//                  a given period. Also routines for changing a calendar month
//                  to a fiscal period, and vice versa.
//
////////////////////////////////////////////////////////////////////////////////
interface

////////////////////////////////////////////////////////////////////////////////
//   Include units
////////////////////////////////////////////////////////////////////////////////
uses
  Windows, SysUtils;

////////////////////////////////////////////////////////////////////////////////
//   Resource strings
////////////////////////////////////////////////////////////////////////////////
resourcestring
  resMonth          =  'Invalid calendar month specified';
  resFiscalMonth    =  'Invalid fiscal month specified';
  resFiscalYear     =  'Invalid fiscal year starting period';

////////////////////////////////////////////////////////////////////////////////
//   Date functions
////////////////////////////////////////////////////////////////////////////////
function   GetFiscalMonth(PostingDate: TDateTime): Word;
function   GetPostingDate(FiscalMonth: Word): TDateTime;
function   FiscalMonthToMonth(FiscalMonth: Word): Word;
function   MonthToFiscalMonth(Month: Word): Word;
function   IsValidPostingDate(PostingDate: TDateTime): Boolean;

////////////////////////////////////////////////////////////////////////////////
//   Determines the month (period) that the fiscal year starts on: valid 1-12
////////////////////////////////////////////////////////////////////////////////
var
  FiscalYearStart:  Word  =  1;

implementation

function GetFiscalMonth(PostingDate: TDateTime): Word;
var  wParts:        Array [0..2] of Word;
begin

  // Decode posting date to get the calendar month
  DecodeDate(PostingDate, wParts[0], wParts[1], wParts[2]);

  // Check posting date against calculated posting date for the period
  result:=MonthToFiscalMonth(wParts[1]);

end;

function IsValidPostingDate(PostingDate: TDateTime): Boolean;
var  wParts:        Array [0..2] of Word;
begin

  // Decode posting date to get the calendar month
  DecodeDate(PostingDate, wParts[0], wParts[1], wParts[2]);

  // Check posting date against calculated posting date for the period
  result:=(Trunc(PostingDate) = GetPostingDate(GetFiscalMonth(PostingDate)));

end;

function MonthToFiscalMonth(Month: Word): Word;
begin

  // Check month
  if not(Month in [1..12]) then raise Exception.CreateRes(@resMonth);

  // Check fiscal year start
  if not(FiscalYearStart in [1..12]) then raise Exception.CreateRes(@resFiscalYear);

  // Remap calendar month into fiscal period
  if (Month >= FiscalYearStart) then
     // Succesor of the difference
     result:=Succ(Month - FiscalYearStart)
  else
     // Subtract and add 12 to the difference
     result:=Succ(12 + (Month - FiscalYearStart));

end;

function FiscalMonthToMonth(FiscalMonth: Word): Word;
begin

  // Check period
  if not(FiscalMonth in [1..12]) then raise Exception.CreateRes(@resFiscalMonth);

  // Check fiscal year start
  if not(FiscalYearStart in [1..12]) then raise Exception.CreateRes(@resFiscalYear);

  // Remap fiscal period into calendar month
  if (Pred(FiscalYearStart + FiscalMonth) > 12) then
     // Handle month wrap
     result:=Pred(FiscalYearStart + FiscalMonth) mod 12
  else
     // No wrap
     result:=Pred(FiscalYearStart + FiscalMonth);

end;

function GetPostingDate(FiscalMonth: Word): TDateTime;
var  wParts:        Array [0..2] of Word;
     wDay:          Word;
begin

  // Decode current date to get the year
  DecodeDate(Now, wParts[0], wParts[1], wParts[2]);

  // Remap fiscal period into calendar month
  wParts[1]:=FiscalMonthToMonth(FiscalMonth);

  // We need to get the first day of the following month and subrtact one to get the last day for the period
  if (wParts[1] = 12) then
  begin
     // Increment the year
     Inc(wParts[0]);
     // Set month to one
     wParts[1]:=1;
  end
  else
     // Increment the month
     Inc(wParts[1]);

  // Set the day to first of month
  wParts[2]:=1;

  // Encode date and subtract one to get last day of month
  result:=EncodeDate(wParts[0], wParts[1], wParts[2]) - 1.0;

  // Check the day of week to figure out where the last friday of the month falls
  wDay:=DayOfWeek(result);

  // Handle the day to determine where friday is
  case wDay of
     // Sunday
     1  :  result:=result - 2.0;
     // Monday
     2  :  result:=result - 3.0;
     // Tuesday
     3  :  result:=result - 4.0;
     // Wednesday
     4  :  result:=result - 5.0;
     // Thursday
     5  :  result:=result - 6.0;
     // Friday
     6  :  ;
     // Saturday
     7  :  result:=result - 1.0;
  end;

end;

end.
Accepted Solution
 
01.23.2008 at 03:04AM PST, ID: 20722336

Rank: Guru

function GetLastFriday(pDate:TDate):TDate;
var pYear,pMonth,pDay:Word;
    pTotalDays,pDayOfWeek:Word;
    pLastFriday:Word;

const
  DaySunday = 1; DayMonday = 2; DayTuesday = 3; DayWednesday = 4;
  DayThursday = 6; DayFriday = 6; DaySaturday = 7;

begin
  DecodeDate(pDate,pYear,pMonth,pDay);
  pTotalDays:=DaysInMonth(pDate);
  pDayOfWeek:=DayOfWeek(pDate);
  pLastFriday:= pDay+ DayFriday-pDayOfWeek;
  if pLastFriday>pTotalDays then Dec(pLastFriday,7);
  pLastFriday:=pLastFriday+(pTotalDays-pLastFriday) div 7*7;
  Result:=EncodeDate(pYear,pMonth,pLastFriday);
end;
 
04.05.2008 at 03:04PM PDT, ID: 21289836
trevsoft,
This question has been classified as abandoned.  I will make a recommendation to the moderators on its resolution in approximately four days.  I would appreciate any comments by the experts that would help me in making a recommendation.

It is assumed that any participant not responding to this request is no longer interested in its final disposition.

If the asker does not know how to close the question, the options are here:
http://www.experts-exchange.com/help.jsp#hi331

mlmcc
EE Cleanup Volunteer
 
04.11.2008 at 12:32PM PDT, ID: 21337437
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup topic area:
   Delete - no points refunded

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

mlmcc
EE Cleanup Volunteer
 
04.11.2008 at 01:07PM PDT, ID: 21337766

Rank: Genius


I object to the delete -  no points refunded, as I believe my code fully addresses the question that was asked (we can only guess, because the asker never replied again)

Regards,
Russell
 
04.16.2008 at 06:58PM PDT, ID: 21373585
Tagged for future cleanup

Computer101
EE Admin
 
05.18.2008 at 12:43AM PDT, ID: 21591864
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup topic area:
   Accept: rllibby {http:#20714927}

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

mlmcc
EE Cleanup Volunteer
 
05.24.2008 at 07:27PM PDT, ID: 21641048
Forced accept.

Computer101
EE Admin
 
 
20080716-EE-VQP-33 / EE_QW_2_20070628