Normal Topic date calculations (Read 676 times)
FSGROUP
Full Member
***
Offline


No personal text

Posts: 179
Location: Edmonton, Alberta, Canada
Joined: Jan 14th, 2004
date calculations
Mar 12th, 2004 at 9:48pm
Print Post Print Post  
are there functions to calculate the number of months or days between two dates?

thanx.
  
Back to top
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: date calculations
Reply #1 - Mar 12th, 2004 at 10:02pm
Print Post Print Post  
@tonumber(date1 - date2 ) should give you number of days between those two dates.

@int (@tonumber (date1 - date2))/30) should give you number of months between those two dates.

I have not tested this but I believe this should work.
« Last Edit: Mar 15th, 2004 at 2:50pm by Bharat_Naik »  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2483
Joined: Aug 20th, 2003
Re: date calculations
Reply #2 - Mar 12th, 2004 at 10:42pm
Print Post Print Post  
@toNumber(Date1 - Date2) gives you the number of days between Date1 and Date2. Date 1 should be the most recent date or the highest date.

Here is a program I just wrote. It figures Years, Months and Days from one date to the next. As always long lines will need to be unwrapped.


Var vPromisedShipDate as Date
Var vActualShipDate as Date
Var vPromisedShipMonth as int
Var vActualShipMonth as int
Var vPromisedShipYear as int
Var vActualShipYear as int
Var vPromisedShipDay as int
Var vActualShipDay as int
var vYearsPassed as int
var vMonthsPassed as int
var vDaysPassed as int

vPromisedShipDate = "4/19/1985"
vActualShipDate = "6/26/1985"

vPromisedShipYear = @Year(vPromisedShipDate)
vActualShipYear = @Year(vActualShipDate)

vPromisedShipMonth = @Month(vPromisedShipDate)
vActualShipMonth =  @Month(vActualShipDate)

vPromisedShipDay = @DOM(vPromisedShipDate)
vActualShipDay =  @DOM(vActualShipDate)

If vActualShipYear >= vPromisedShipYear then
{
     if vActualShipMonth >= vPromisedShipMonth then
     {
           if vActualShipDay > vPromisedShipDay then
           {
                 vYearsPassed = vActualShipYear - vPromisedShipYear
                 vMonthsPassed = vActualShipMonth - vPromisedShipMonth
                 vDaysPassed  =       vActualShipDay - vPromisedShipDay
                 WriteLn("This Product Shipped " + @str(vYearsPassed) + " Years, " + @str(vMonthsPassed) + " Months, and " + @str(vDaysPassed) + " Days later than it was supposed to")
           }
           else if vActualShipDay = vPromisedShipDay then
           {
                 //The product shipped exactly on the day it was supposed to
                 WriteLn("We should buy from this company more often. Product was shipped on date it was supposed to be shipped on.")
           }
           else
           {
                 //Product shipped sooner than expected same month but earlier day
                 WriteLn("This product was shipped at least a day before it was expected to be.")            
           }
     
     }
     else
     {
           //Product was shipped atleast a month before it was expected to
           WriteLn("This product was shipped at least a month before it was expected to be")            
     }
}
else
{
     //Product was shipped at least a year before it was expected to
     WriteLn("This product was shipped at least a year before it was expected to be")
}
« Last Edit: Mar 15th, 2004 at 2:21pm by Ray the Reaper »  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
GW
Junior Member
**
Offline


No personal text

Posts: 83
Joined: Dec 16th, 2003
Re: date calculations
Reply #3 - Mar 13th, 2004 at 4:41pm
Print Post Print Post  
Ray, can I suggest you place the above programming into the "Programme Examples" directory of the forum.
Would be easier to find when searching for examples at a later date.
thanks becky
  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2483
Joined: Aug 20th, 2003
Re: date calculations
Reply #4 - Mar 15th, 2004 at 2:25pm
Print Post Print Post  
Yes becky that was actually the first thing on my list for today. The program can now be found in the "Programming Examples" section of the forum.
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: date calculations
Reply #5 - Mar 15th, 2004 at 3:47pm
Print Post Print Post  
Quote:
Yes becky that was actually the first thing on my list for today. The program can now be found in the "Programming Examples" section of the forum.


Thanks Ray.

Any time you want to give more examples we out here are ready to use them.  Grin

Seriously Thanks for the info. Smiley

  

Team – Together Everyone Achieves More
Back to top
 
IP Logged