Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

366
Views
converting month to year usig js in laravel project

if we consider X as month i want to check if X was bigger than 24, then divide it in 12 and return a number otherwise if it was smaller than 24 i want the code to return X itself.

note that the project is in Laravel and i want to do this with inline JavaScript code.

i tried to do it this way

<script>
const guaranteeTime = "{{$product->guarantee_time}}"

function guaranteeConvert() {
   const guaranteeTimeNew = guaranteeTime / 12;
}

if (guaranteeTime > 24) {
  guaranteeConvert();
}



</script>

thnaks

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You can get php variable in JS like this:

const guaranteeTime = {!! json_encode($product->guarantee_time) !!};
about 4 years ago · Juan Pablo Isaza Report

0

You need to parse value to Integer. Like below

const guaranteeTimeNew = parseInt(guaranteeTime) / 12;
about 4 years ago · Juan Pablo Isaza Report

0

Hi There You can do it Like this :

function MonthToYear(x) {
let result='';
if(x>24)
       {
         result=parseInt(x/12)+"Year/s";
         if(x%12!=0)
         result=result+" and "+x%12+" Month/s";
        
         return result;}
else return x;
                         }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!