I have 2 date fields issued date and due date.When I choose issued date,due date should be auto populated by adding 10days with selected date. I have written on-change method for this
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//var issuedDate=new GlideDateTime(g_form.getValue('u_issued_date'))
//var issuedDate=g_form.getValue('u_issued_date')
alert(issuedDate)
var gdt = new GlideDateTime(issuedDate);
gdt.addDays(10)
g_form.setValue('u_due_date',gdt);
}
I am getting an error GlideDateTime is not defined function ().How can I achieve this? Is there any other way?
GlideDateTime is not available on client side. For simple operation like the one you are having you can use javascript Date object. Which is pain to format, but doable, example:
var date = new Date(g_form.getValue('u_issued_date'));
date.setDate(date.getDate() + 10); //add 10 days
g_form.setValue('u_due_date', formatDate(date));
function formatDate (date) {
return date.getFullYear() + '-' +
leadingZero(date.getMonth() + 1) + '-' +
leadingZero(date.getDate()) + ' ' +
date.getHours() + ':' +
date.getMinutes() + ':' +
date.getSeconds();
}
function leadingZero (value) {
return ("0" + value).slice(-2);
}
For more complicated operation you would wish GlideDateTime you will have to use GlideAjax, that will do operations on server side, and provide result.
Related
When the user select a range of dates on the calendar, a modal opens and the input fields of initial and final dates are auto complete with the dates selected previously. The problem is that they are displaying in this format YYYY-MM-DD and I want it to be DD-MM-YYYY. I have tried everything but nothing seems to work.
Here is where I get the dates and fill the inputs:
select: function (info) {
$('#ModalAdd').modal('show');
$('#ModalAdd').appendTo("body");
$('#activoReservar').val($('#selectActivoReserva option:selected').text());
$('#fechaInicial').val(info.startStr);
var endDate = new Date(info.end);
var beforeDay = new Date(endDate.getFullYear(),endDate.getMonth(),endDate.getDate() - 1).toISOString().slice(0,10);
$('#fechaFinal').val(beforeDay);
},
And here are the things I have tried:
$('#fechaInicial').val(info.startStr.format('ddd, DD-MM-YYYY')); //i tried with dd and a single d too. And without any d
$('#fechaFinal').val(beforeDay.format('ddd, DD-MM-YYYY'));
you may create another function (which you can use anywhere else too),
pass a date to that function and return your desired format.
The sample function might look like as follow:
function dateToDMY(date) {
var d = date.getDate();
var m = date.getMonth() + 1; //Month from 0 to 11
var y = date.getFullYear();
return '' + (d <= 9 ? '0' + d : d) + '-' + (m <= 9 ? '0' + m : m) + '-' + y;
}
And you may call the function from select or any other place as follow:
select: function (selectionInfo) {
var startStr = dateToDMY(selectionInfo.start);
}
I'm working on a basic email-sending script in Google Sheets. I want to send email reminders on clicking a button, reminding people of an appointment at a date and time along with the location.
Everything works, except for the date is displayed in a confusing long form format:
The data shown in the date and time cells is:
8/27/2018
10:30 AM
The data being sent in the email is:
Mon Aug 27 2018 15:00:00 GMT+0800 (HKT)
Sun Dec 31 1899 02:30:00 GMT+0800 (HKT)
I only need to show the date and time as written in the sheets. Is there a way to do this?
Another question is that one person might have more than one appointment, can I combine all appointments date/time for each unique email address into one email instead of multiple emails?
Adding code below:
function sendArticleCountEmails() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.setActiveSheet(ss.getSheetByName("SSname"));
var sheet = SpreadsheetApp.getActiveSheet();
var dataRange = sheet.getRange("B2:O2");
var data = dataRange.getValues();
for (i in data) {
var rowData = data[i];
var emailAddress = rowData[0]; //email
var recipient = rowData[1]; //name1
var message2 = rowData[2]; //Name2
var message3 = rowData[3]; //type
var message4 = rowData[4]; //Appt Date
var message5 = rowData[5]; //Appt Time
var message6 = rowData[6]; //Appt type
var message7 = rowData[7]; //Notes
var message8 = rowData[8]; //Facility Name
var message9 = rowData[9]; //Facility Address
var message10 = rowData[10]; //City
var message11 = rowData[11]; //Zip
var message12 = rowData[12]; //Phone
var message13 = rowData[13]; //Service
var message = 'Dear ' + recipient + ',\n\n' + 'This is a friendly reminder of your assignment tomorrow with:' + '\n\n' + message2 + ' at ' + message5 + '.'
+ '\n\n' + 'The assignment is located at ' + message8 + ', ' + message9 + ', ' + message10 + ', ' + message11 + '.' + '\n\n'
+ 'This assignment is noted as a ' + message6 + ' ' + message3 + ' ' + message13 + '. ' + message7 + '\n\n';
var subject = 'Reminder: ' + message4 + ' ' + message5 + ' (' + message2 + ')';
MailApp.sendEmail(emailAddress, subject, message);
}
}
I think the problem is here, using either var or rowData. The row is correct, just it doesn't pull the data in as shown in Sheets.
var message4 = rowData[4]; //Appt Date
var message5 = rowData[5]; //Appt Time
There is no time in the DATE cell (8/27/2018), so I'm guessing it defaults to "15:00:00" and because my data is input by mailparser, I don't have a method to change the format of the data. Rather I hope I can use the data as displayed in Google Sheets and display this into the Gmail.
I appreciate your suggestions in advance, thanks!
i am using below function to convert my json date /Date(1450314910930)/
function jsonDateConvert(MyDate_String_Value)
{
var value = new Date
(
parseInt(MyDate_String_Value.replace(/(^.*\()|([+-].*$)/g, ''))
);
var dat = value.getMonth() +
1 +
"/" +
value.getDate() +
"/" +
value.getFullYear();
return dat;
}
My original date in database is 12/16/2015 but above function gives me +1 day ahead like 12/17/2015 please help me to get original date
Try like this,
function jsonDateConvert(MyDate_String_Value)
{
var d=new Date(MyDate_String_Value);
var dat = d.getMonth() +1 +"/" + d.getDate() +"/" +d.getFullYear();
document.getElementById("date_input").value = dat;
}
jsonDateConvert("12/16/2015")
<input type="text" id="date_input" />
I'm trying to use firebase function transaction, but as I see there is no official way to handle the first cached null value...
I'm trying to do the following:
var team = event.data.child('team').val();
var tip = event.data.child('tip').val();
console.log('tip: ' + tip + ' | team: ' +team)
const pathToValue = admin.database().ref('users/' + event.params.userId + '/coins');
const pathToTeamBetsValue = admin.database().ref('matches/' + event.params.matchId + '/opponents/' + team + "/bets");
return pathToValue.transaction(function (coins) {
if (coins) {
if (coins >= tip) {
pathToTeamBetsValue.transaction(function (teamBets) {
if (teamBets) {
teamBets = teamBets + tips;
return teamBets;
}
});
admin.database().ref('bets/' + event.params.matchId + '/' + event.params.userId + '/status').set('inProgress');
coins = coins - tip;
}
else {
console.warn(event.params.userId + " new bet on match " + event.params.matchId + " was not successfull! (not enough coin)")
//return coins;
}
}
return coins;
})
so far as you can see I get some value which what should be decreased from the user's coins... unfortunately till now I could only get the behaviour which sets null in the user's coin value.. please help
I am using jquery easyui edatagrid, where one column is of datebox type editor.
I want to auto select today date so that data entry is faster.
Code :
<th field="date" width="50" editor="{type:'datebox',options:{formatter:myformatter,parser:myparser,required:true}}">Date</th>
function myformatter(date){
var y = date.getFullYear();
var m = date.getMonth()+1;
var d = date.getDate();
return (d<10?('0'+d):d)+'/'+(m<10?('0'+m):m)+'/'+ y;
}
function myparser(s){
if (!s) return new Date();
var ss = (s.split('/'));
var d = parseInt(ss[0],10);
var m = parseInt(ss[1],10);
var y = parseInt(ss[2],10);
if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
return new Date(y,m-1,d);
} else {
return new Date();
}
}
You can set the date as soon as the grid data is loaded. For example, something like
$('.datebox input').each( function(){ $(this).val(formatDate(new Date())) });
It is a matter of getting the input fields. For me the above works, you can adjust it according to your code. Then you need a function that does the date formatting, for example
function formatDate(value) {
return value.getMonth()+1 + "/" + value.getDate() + "/" + value.getYear();
}