I'm trying to send a table from google sheets to gmail using apps script, i have multiple dates and i want to send in this format "dd-mm-yy", but the problem is that i need to use utilites.formatdate which coverts the cell into string, so when i try to send the email it diplays that the parameters dont match the method, i think this is because in some cells date could be not fullfilled, so theres nothing written in the cell, because of this error i cant send the email, if i write dates in the cells it works but there are cases when they are not fullfilled as i said, how can i solved this problem and send the email no matter if all the dates are filled or not?
var fecha = registro.getRange("c16").getValue();
var fechaF = Utilities.formatDate(fecha, "GMT","dd-MM-YY");
This is the way i tried to change the format, and if there is someting written works but
var fecha2 = registro.getRange("e16").getValue();
var fecha2F = Utilities.formatDate(fecha2, "GMT","dd-MM-YY");
In the second there is nothing so it displays the error
Hope you can help me guys
I'm learning so all kind of advices you give to me are welcome
Try this:
var fecha = new Date(registro.getRange("c16").getValue());
var fechaF = Utilities.formatDate(fecha, "GMT","dd-MM-YY");
Try to initiate Date by adding new DATE() to use the converted string as DATE type and after that you can format it as you want
so your code will be
var fecha = new DATE(registro.getRange("c16").getValue());
EDIT
var fechaF = Utilities.formatDate(fecha, "GMT","dd-mm-yyyy").setNumberFormat('dd-mm-yyy');
Related
I'm Attempting to create a Merge between some sheet Data, a doc template and a final doc template.
Mainly, I have access to these files like this:
var contratotemplate = DocumentApp.openById(contratotemplateId);
var contratonovo = DocumentApp.openById(contratonovoId);
var ws = SpreadsheetApp.openById(planilhaId).getSheetByName("Contratos Ref Marca");
Than, used this code to pick each Data from a Range that I want.
var data = ws.getRange(3,1,1,ws.getLastColumn()).getValues();
The Problem is here when I try to replacetext with cell information from my sheet trough another function callback (the one that actually replace text with info):
data.forEach(function(r){
CriarMailMerge(
r[30].getDate()+"/"+r[30].getMonth()+"/"+r[30].getFullYear(),
paragrafosTemplate,
contratonovo);
});
The result is this:
11/5/2019 //in contratonovoId field supposed to have the correct date.
I've already tried .toLocaleDateString()
The result is:
June, 11 2019.
Which solves my problem, but I can't find a way to bring that info into Brazilian Portuguese.
Can u guys help me?
I Used this and worked:
r[30].getDate()+"/"+("0" + (r[30].getMonth() + 1)).slice(-2)+"/"+r[30].getFullYear(),
RESULT
11/06/2019
I am using google chrome and trying to build a messaging system. I need to display date/time of messages. I used date function but it is giving 'NaN' error. It works fine if I directly pass value, but with a variable input. It fails. I searched for the answer but I am unable to identify problem. below is my code.
var d = jsarr[j];// sets d = 1448702771436
alert(d); //1448702771436
var date = new Date(d);
alert(date); //invalid date
I tried parsing 'd', with parseInt() and now it works fine. #Andreas I even tried parsing well before but somehow it was not working back then. Thanks any ways.
Might be because of uncleared cache, I hard refreshed. using ctrl + F5
var d = jsarr[i];
var s = parseInt(d);// changing type to Int
var date = new Date(s); // valid date
I am needing to generate a field with the next date after a user inputs one date in a PDF using Javascript. Here is my code so far:
var numDaysToAdd = 1;
var inputDateString = getElementById("Date.1").value;
var resultDate = stringToDate(inputDateString);
resultDate.setDate( resultDate.getDate()+numDaysToAdd );
var result = dateToString( resultDate );
event.value = result;
Using this code, I get no return in the field. If I input "11.23.15" instead of the get Element for inputDateString, I get the result "12.11.16". So I have two issues - it doesn't seem to be pulling the value from Date.1, and when I add one day, it adds a whole lot more than a day. Thanks for the help.
You may be aware that Acrobat JavaScript (which is used within PDF) has a completely different object model than webbrowser JavaScript. It is therefore highly recommended to get the Acrobat JavaScript documentation, which is part of the Acrobat SDK documentation, downloadable from the developer section of the Adobe website.
That said, you would add the following to the Calculate event of the field where the result should appear (we assume that the date in the field "Date.1" has the format "MM/DD/YYYY"):
var numDaysToAdd = 1 ;
var fromDate = util.scand("mm/dd/yyyy", this.getField("Date.1").value) ;
var toDate = fromDate ;
toDate.setDate(fromDate.getDate() + numDaysToAdd) ;
event.value = util.printd("mm/dd/yyyy", toDate) ;
And that should do it.
In my table date is listed as "2015-07-31 06:02:20". How can I get date and time separately using jQuery?
I used some code but it shows some errors.
var timestamp = new Date(data.responsecusthistory.created_at);
var date = timestamp.toDateString();
Error: Invalid Date
var date = data.responsecusthistory.created_at.split(" ")[0];
var time = data.responsecusthistory.created_at.split(" ")[1];
If you want to have a time string (i.e. HH:MM:SS), try e.g. this:
var timestampTime = timestamp.toTimeString().split(' ')[0];
Anyway, there's no obvious reason why you get the "Error: Invalid Date", as long as
data.responsecusthistory.created_at
is a correct value, such as "2015-07-31 06:02:20". Please consider double-checking this variable.
Try this:
dateString= "2015-07-31 06:02:20";
temp = new Date(dateString);
dateStr= $.datepicker.formatDate('mm/dd/yy', temp );
for getting different formats check the link https://github.com/phstc/jquery-dateFormat.
Using different formats we will get different date, time etc in which ever forms we need it.
I have a problem that is breaking my head since yesterday and don't know how to deal with it.
I have a date field in my database that contains the following value:
Then my application get the value and send that to my web form. (the value still the same :) thats fine!!
In client side I put a break with a javascript alert to see the value that is comming from JSON (the value still the same :) thats fine!!
The code in client side for the alert is this:
// transaction json model
var jsonTransaction = #(Html.Raw(Json.Encode(this.Model.Transaction)));
alert(new Date(parseInt(jsonTransaction.Date.substr(6))));
Now when I send back the value to the server this is what I get
And finally after deserialization of the JSON my date time is wrong!! instead of Day 7 its now Day 8???????
This is the code for deserializing:
public JsonResult SaveBill(string jsonTransaction, string jsonTranDetails)
{
_appState = this.AppState;
JsonResult returnVal = returnVal = Json(
new { Success = true }
);
var transaction = JsonConvert.DeserializeObject<BillTransaction>(jsonTransaction, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore });
Any clue on how to solve this issue with dates, I should get the same date because I didn't change anything. Hope someone can guide me for a solution.
Thanks in advance.
Java script use universal time when it parse the date as currentdate = new Date(123232)
so when you send date to client convert it to ISO date such as
make sure the date is in UTC before convering it to strong .
return String.Format("{0:yyyy-MM-ddTHH:mm:ss.fffZ}", dt);
bty I already created JSON Converted to override any date serialization to client side to use the above function .