# to add a function in a php file

We have a php file that get a price from a database using this URL (that provides 3 variables: breed + age + postalcode)

Now we need that the age variable, instead of being by years (1,2,3,4…), should be by date: 27/01/2018

like in here: [login to view URL]

For that I need to include a function that convert the age date from a date (27/01/2018) to a year range…

Dates from 1 day to 1 year, should be 1

Dates from 1 year to 2 ears should be 2

Dates from 2 years to 3 years should be 3

Etc…

i.e. 27/01/2018 should be converted to 2 , because from that date to today there is more than 1 year and less than 2 years.

I have already the function, but I don’t know hoy to include it in the api

See the function below:

function age_range(\$initial_date){

\$initialdate = new DateTime(\$initial_date);

\$finaldate = new DateTime('now');

\$diference = \$initialdate->diff(\$finaldate);

// the diff method provide an objet DateInterval,

// that keeps the information about the differnet time period

// between dates (yeasr, months, days, etc.).

\$months = ( \$diference->y * 12 ) + \$diference->m;

// To calculate the number of months we have to multiply “y” times 12

// (number of months in a year). After that we add the value saved

// to “m“, that contains the number of months of our age range.

/*

1 is from 2 months upto 1 year

2 is from 1 year upto 2 year

3 is from 2 upto 3

4 is from 3 upto 4

5 is from 4 upto 5

6 is from 5 upto 6

7 is from 6 upto 7

*/

if ( \$months >= 2 and \$months <= 12 ) { return 1; }

if ( \$months >= 13 and \$months <= 24 ) { return 2; }

if ( \$months >= 25 and \$months <= 36 ) { return 3; }

if ( \$months >= 37 and \$months <= 48 ) { return 4; }

if ( \$months >= 49 and \$months <= 60 ) { return 5; }

if ( \$months >= 61 and \$months <= 72 ) { return 6; }

if ( \$months >= 73 and \$months <= 95 ) { return 7; }

}

Skills: HTML, Javascript, MySQL, PHP, Software Architecture

( 22 reviews ) Sevilla, Spain

Project ID: #19620881

## Awarded to:

RanjitRimpi

Greetings, I understood what you are trying to achieve but than I am little confused too. You are saying that below API call gives you price- [login to view URL] More

€16 EUR in 1 day
(6 Reviews)
2.1

## 38 freelancers are bidding on average €26 for this job

I am experienced php developer and web designer with the depth knowledge related to MySQL,Laravel,WordPress,MSSQL,JSON,JAVASCRIPT,AJAX,XML,jQuery,CSS,HTML5,Material Designing with the integration of web technologies. More

€29 EUR in 1 day
(418 Reviews)
7.3
PhungTran

Hi I can write the function as you want. Hire me please. Thank you! .

€20 EUR in 1 day
(611 Reviews)
7.1
yogeshssanwal

Hello, I read your Job Description and I can add a function into the PHP file of API and complete your Project perfectly, you will get satisfied result… I have Skills in PHP, MySQL, HTML5, CSS3, LESS/Sass/SCSS, JavaScr More

€35 EUR in 2 days
(274 Reviews)
7.2
ineedWorkJob

Greetings sir, I have read your project details and i will add the function to your php file right away. Sir, i can deliver this project sooner than you expect and will be over your satisfaction level. Please More

€30 EUR in 1 day
(194 Reviews)
7.1
bjrupani

Hello hiring member i hope you are doing well i am bhavika i have 3+years experience in php ,laravel , ajax , jquery , javascript , html ,css , bootstrap so i can do it so please give me chance to serve you thanks in a More

€30 EUR in 1 day
(180 Reviews)
6.7
csajit

Lets get it done. I am available to take up this job. Please check my reviews and then decide on me. PHP Programmer with 10+ years of experience. Please let me know if you have any questions. Thanks, Ajit

€25 EUR in 1 day
(285 Reviews)
6.8
webperfection123

Hi There, I can add a function in a php file.I have read your job description and assure you that I am a perfect fit for the job. My Expertise:- =========== > PHP, HTML, CSS, javascript/jquery, API integration,Word More

€30 EUR in 1 day
(154 Reviews)
6.9
natgeo

Hello, I have 18 years of coding experience. This is a very easy task for me which I can accomplish within a couple of hours. Ready to fix it right away for you. Thanks

€14 EUR in 1 day
(136 Reviews)
7.1
aftabyounas

Hi, I have read your project description this will be done in your required time spam with 100% Satisfaction. Kindly message me so we can discuss in detail over chat......

€17 EUR in 1 day
(143 Reviews)
6.6
€29 EUR in 1 day
(289 Reviews)
6.7
webteklab

Hi, I have checked the work scope and can fixed the date format too " (27/01/2018) " Please initiate a chat session for more discussion about the project. I am looking forward to working with you. Thanks for readin More

€50 EUR in 1 day
(142 Reviews)
6.5
techplusintl

Hi there, Greetings from TechPlus! I've reviewed requirements & ready to add a function in a php file. 5+ Years Expertise in : CMS (Wordpress, Magento, Shopify, OpenCart, Joomla, Drupal, Prestashop) PHP Fram More

€30 EUR in 1 day
(117 Reviews)
6.4
articontech

I have being working as php developer since 8 years in which 4 Years I have being working as joomla developer. I have also worked in Magento, cake php, wordpress, prestashop, boonex, osccomerce, opencart ect websites w More

€23 EUR in 1 day
(101 Reviews)
6.0
piyushccet

Hey, I have gone through your post and pretty simple to add this function into code but before that I need to study your code so I can provide you best solution at reasonable price. Let's connect to discuss your re More

€30 EUR in 1 day
(42 Reviews)
5.7

Hi I am software engineer and full stack PHP developer your project is looking very interesting and I am looking forward to your message

€24 EUR in 1 day
(103 Reviews)
5.9
czarneckim

Hello there, I have got 5 years of web development experience including PHP, MySQL, Laravel, I can work on that function for you and I can start work immediately.

€25 EUR in 1 day
(16 Reviews)
5.6
Zaiyan

Hello, I can do the work and can start working now. Please message me for further discussion. Best Regards, Zaiyan

€23 EUR in 1 day
(45 Reviews)
5.5
alkajain2906

Greetings, Thank you for posting a Job. I WILL DO THIS AS PER YOUR REQUIREMENT AND EXPECTATIONS. With the experience of over 300+web development projects including ANDROID, IOS, WEBSITES, WEB APPLICATIONS AND SOFTWARE More

€23 EUR in 1 day
(39 Reviews)
5.4
AndITServices

Hi, I have read your project description. I am very confident to provide your PSD to Wordpress design. I have great experience in Wordpress, Shopify, Woo-Commerce, Php, Javascript, HTML5, CSS3 with Bootstrap Res More

€20 EUR in 1 day
(62 Reviews)
5.8
CodeShood

Hello, I consider myself appropriate for this project. I am Software Engineer since 2013, I have completed more than 30+ successful mobile apps of iOS and Android. I have also completed more than 25+ successful website More

€23 EUR in 1 day
(20 Reviews)
5.3