
PRO
dbeard
USA
Asked
— Edited

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.
I have often wanted to try it but other more important things come up.
Code:
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
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.
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/////////////////////////////////
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.