Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DateDiff seperated by Months

Status
Not open for further replies.

Laurelin

Programmer
Jan 24, 2002
29
0
0
US
I am trying to calculate the number of days between two date and show how many days in each month are between the two dates.

Example:

Start Date: 7/13/2010
End Date: 2/7/2011

I want the report to show me the number of days that are used between those two days by month. Number of days in July, August, Sept....etc..

Any ideas?
 
Use formulas like this:

//{@July days}:
datevar st := {table.startdate};
datevar end;
numbervar jul;
if st < date(2011,7,1) then
st := date(2011,7,1) else
if st >= date(2011,8,1) then
st := date(0,0,0) else
st := st;
if isnull({table.enddate}) then
end := date(2011,7,1) else
end := {table.enddate};
if end < date(2011,7,1) or
st := date(0,0,0) then
end := date(0,0,0) else
if end >= date(2011,8,1) then
end := date(2011,7,31) else
end := end;
end-st+1 //+1 to count both start and end dates in difference

-LB
 
Oh wow, that looks great. Why is telling me that a Boolean is Required Here?

//{@July days}:
datevar st := {table.startdate};
datevar end;
numbervar jul;
if st < date(2011,7,1) then
st := date(2011,7,1) else
if st >= date(2011,8,1) then
st := date(0,0,0) else
st := st;
if isnull({table.enddate}) then
end := date(2011,7,1) else
end := {table.enddate};
if end < date(2011,7,1) or
st := date(0,0,0) then
end := date(0,0,0) else
if end >= date(2011,8,1) then
end := date(2011,7,31) else
end := end;
end-st+1 //+1 to count both start and end dates in difference


 
//{@July days}:
datevar st := {table.startdate};
datevar end;
if st < date(2011,7,1) then
st := date(2011,7,1) else
if st >= date(2011,8,1) then
st := date(0,0,0) else
st := st;
if isnull({table.enddate}) then
end := date(2011,7,1) else
end := {table.enddate};
if end < date(2011,7,1) or
st = date(0,0,0) then [red] shouldn't have had a colon[/red]
end := date(0,0,0) else
if end >= date(2011,8,1) then
end := date(2011,7,31) else
end := end;
end-st+1 //+1 to count both start and end dates in difference

Also I removed the "numbervar jul" since I ended up not using it.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top