Welcome to Synthiam!

The easiest way to program the most powerful robots. Use technologies by leading industry experts. ARC is a free-to-use robot programming software that makes servo automation, computer vision, autonomous navigation, and artificial intelligence easy.

Get Started
Asked — Edited
Resolved Resolved by CochranRobotics!

Calculating Number Of Days Between 2 Dates

Has anyone a piece of script code that will calculate how many days have past since the current date? I need to do the calculation, but I believe the dates are alphanumeric and not numeric and cant figure it out.


ARC Pro

Upgrade to ARC Pro

Experience early access to the latest features and updates. You'll have everything that is needed to unleash your robot's potential.

AI Support Bot
Related Content
Synthiam
#1  
This interests me too.
I have often wanted to try it but other more important things come up.
#2  
It is actually numeric. You need to do something like this:

Code:


#code to pull and set the starting day
$szStartDay = $Day
#your code runs for a certain amount of days

#code to pull and set the current day
$szCurrentDay = $Day
#code to do the math to figure out how many days passed
PRO
USA
#3  
How do you handle the calculation if the time spans multiple months?
United Kingdom
#4  
@dbeard.

I've posted the following link to a thead where I asked for script advice for a robot to say exactly how old it is. It uses the day, month ect, variables to set an age and then calculates his age using the computers clock whenever asked. You might be able to get some useful info from the scripts @Rich posted for me, as they are based on the same princible to what you're looking for. Hopefully you can find some useful elements from the scripts to make what you're looking to do. Hope it helps.

Asking a robot for its age scripts
PRO
USA
#5  
Steve, thanks for the information. but I need it down to the day level, not years. I cant figure out how to count the days, when some months have more days then others. I am trying to figure out the number of days that have elapsed over time.
#6  
If you are going to use a database as your other pose suggests, I would pass the dates to a function in the database to do this. It would have a date different function.
PRO
USA
#7  
No, actually two different things. The date calculation is to count days, unrelated to the calendar. more of an elapsed days counter.
#8  
If you have the tools available in the database, why not just use them to do what you need to do? If you have it, use it. It can easily be passed back into ARC via a variable. As you would want an app to access the database anyway, you could also just do the date diff function inside of the app. You can pass switches to the application to have it perform specific tasks. You would also be able to include the dates you want to compare.

It might be possible in a script. I don't know. I personally call could based services to do this. Wolfram alpha allows personal users to make an api that can handle 2000 calls a month. It handles these types of questions very well.
PRO
USA
#9  
What is a wolfram alpha? I am a beginner, trying to learn ez robot script language. I was hoping I could see an example of someone else's script language. But maybe no one has done anything like this before. I do appreciate your comments d.cochran but you are definitely an advanced user.

I have seen examples of this being done in c++ but not sure how to put it into script language. see below (partial code I found)


Days in-between dates



002
// Compiled in Visual C++ 2008 Express Edition



003
// Language: C++/STL



004




005




006
#include<iostream>



007




008
using namespace std;



009




010




011




012




013
int main()



014
{



015




016
int days_in_months[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};



017




018
int first_day, second_day;



019




020
int first_month, second_month;



021




022
int first_year, second_year;



023




024
int years_difference, days_difference;



025




026
int months_total;



027




028
int reg_year = 365;



029




030




031




032
cout<<"Program to calculate how many days are in between the day/month/year entered."<<endl;



033
cout<<endl;



034




035
cout<<"Please enter the date by day, month, year."<<endl;



036
cout<<endl;



037




038
cout<<"First date:: "<<endl;



039
cout<<endl;



040




041
cout<<"Day: ";



042
cin>>first_day;



043
if(first_day > 31 || first_day <= 0)



044
{



045
cout<<"Incorrect day entered"<<endl;



046
cin.ignore();



047
return 0;



048
}



049
cout<<"Month: ";



050
cin>>first_month;



051
if(first_month > 12 || first_month <= 0)



052
{



053
cout<<"Incorrect Month entered"<<endl;



054
cin.ignore();



055
return 0;



056
}



057
cout<<"Year: ";



058
cin>>first_year;



059
if(first_year > 9999 || first_year < 0)



060
{



061
cout<<"Incorrect Year Entered"<<endl;



062
cin.ignore();



063
return 0;



064
}



065




066
cout<<endl;



067
cout<<"\nSecond date:: "<<endl;



068
cout<<endl;



069




070
cout<<"Day: ";



071
cin>>second_day;



072
if(second_day > 31 || second_day <= 0)



073
{



074
cout<<"Incorrect day entered"<<endl;



075
cin.ignore();



076
return 0;



077
}



078
cout<<"Month: ";



079
cin>>second_month;



080
if(second_month > 12 || second_month <= 0)



081
{



082
cout<<"Incorrect Month entered"<<endl;



083
cin.ignore();



084
return 0;



085
}



086
cout<<"Year: ";



087
cin>>second_year;



088
if(second_year > 9999 || second_year < 0)



089
{



090
cout<<"Incorrect Year Entered"<<endl;



091
cin.ignore();



092
return 0;



093
}



094




095




096
/////////////////////////////Years/////////////////////////////////
#10  
This code just sets up the parameters and then asks for the dates. It does some validation on the dates but doesn't do any calculations. I assume that the remainder of the code has been truncated?
PRO
USA
#11  
correct. I wasn't going to paste the whole thing, just show an example of it being done through code.
United Kingdom
#12  
Okay no worries. I just wanted to mention that the scripts in the birthday link don't just use years, but months as well, and using the date/time variables, you can also do days, hours, or minutes if desired. Can you give us an application example of what you would use this kind of script for, it might help give us to guide you better.
PRO
USA
#13  
sure. I am going to use the calculation to determine how many days have gone past since a particular update. I can figure it out as long as it happens within the month. My problem is when the days go across a month how to figure it out. I have to calculate, what month, how many days in the month, etc...

Nothing to do with a calendar or birthdays. If the update is 2 days old I want to take one action if 3 days old another action. In no scenario do I see the elapsed time being over 3 days. so never months or years. I played around with it some, but cant figure out how to even compare one date to another, the script wants to treat the date as a alphanumeric, not numeric. so things line < > don't work at least for me.

hope that helps.
United Kingdom
#14  
Okay thanks for that. That makes it a lot clearer to what you're looking to do. I won't be near a computer with ARC on it for a day or two, but when I get a chance I'll see if I can work something out for you, unless somebody else comes up with a solution of example in the mean time.
PRO
USA
#15  
that works for me. thanks for your time.
PRO
USA
#16  
Had to pick someone. But certainly Steve G. assisted.