Subtraction with date - Google Apps Script

Asked

Viewed 1,013 times

0

Expensive,

I need to calculate how many days remain to reach the expected date.

I’m getting the following values

var dataPrev = row[4]; //26/01/2018
var dataNaoFormat = new Date(); //22/01/2018

I’m making the following calculation:

var sub = dataPrev - dataNaoFormat;

And the result is :

2.65807814E8

Apart from the scientific format, 26,580,781.400 million.00

I need you to call me back a full number, in which case it would be 4.

2 answers

0


    var row = data[i];
    var dataCarimbo = Utilities.formatDate(new Date(row[0]), "GMT", "dd/MM/yyyy");
    var dataForm = new Date(row[1]);
    var email = row[2];
    var dataPrev = row[4];
    var opcao = row[3];

    var timeDiff = Math.abs(dataPrev.getTime() - dataForm.getTime());
    var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));

Seen on topic: Calculate difference between two dates to validate date fields

0

Can’t you use any js library to handle these dates? There is a momentJs call https://ifpb.github.io/jaguaribetech/2016/09/01/moment-js/

With her you can treat it very easily.

Follow an example in php too if it helps:

$date = new DateTime("NOW");
echo $date->format('Y-m-d')."<br>";

//subtrai mês da data atual
$date = $date->sub(DateInterval::createfromdatestring('+ 1 month'));
echo 'Subtraindo 1 mês: '.($date->format('Y-m-d')).'<br>'; 

//Adiciona 1 mês a data
$date = $date->add(DateInterval::createfromdatestring('+ 1 month'));

//Recarrega mês atual
echo 'Adicionando 1 mês'.($date->format('Y-m-d')).'';

Browser other questions tagged

You are not signed in. Login or sign up in order to post.