Organizing dates with Google Apps Script in a two-column format

I am trying to combine 2 cells in apps script to generate a single date for adding an event to my calendar.

 function ConcatenateDateCells () {
  var spreadsheet = SpreadsheetApp.getActive();
  var sheet1 = spreadsheet.getSheetByName("TABLEAU DE BORD") 
  var clientName = sheet1.getRange("D4").getDisplayValue(); // Client's name
  var title = sheet1.getRange("E5").getDisplayValue(); // Event title
  var calendar = CalendarApp.getDefaultCalendar(); // Default calendar

  var rawDate = sheet1.getRange('H13').getValue(); // Date: 22/12/2016
  var time = sheet1.getRange('I13').getValue(); // Time: 18:00

  var formattedDate = rawDate + " " + time;

  calendar.createEvent(clientName + " : " + title, formattedDate, formattedDate);
}

I want the formatted date to be: Thu Dec 22 2016 18:00:00 GMT+0100 (CET)

Would this formatting be achievable? Apologies for any language errors (French is my native language).

Answer №1

I encountered a similar situation and successfully resolved it using the following method:

function customFunction()
{
  var sheet = SpreadSheetApp.openById("ID-Of-the-Sheet").getSheetByName("Name-of-the-Sheet");
  var data = sheet.getDataRange(2,1,sheet.getLastRow(),sheet.getLastColumn()).getValues();

  var date = data[rowIndexOfDate][columnIndexOfDate];
  var time = data[rowIndexOfTime][columnIndexOfTime];

  var eventDateTime = setTimeIntoDate(date,time);

  //You can add your event creation logic here
}

function setTimeIntoDate(date,time) //Custom function to set time into date
{
  var t = time.split(":"); //Assuming time format like "HH:mm:ss"

  var modifiedDate = new Date(date.setHours(t[0],t[1],t[2],0));
  return modifiedDate;
}

Answer №2

Give this a shot:

date.setHours(heure.getHours());
date.setMinutes(heure.getMinutes()); // Adjust as needed for minutes
date.setSeconds(heure.getSeconds()); // Adjust as needed for seconds

Executing this code will sync the time of date with that of heure.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to efficiently filter an array in React without ending up with an empty result?

I am currently facing an issue with filtering an array of users based on an input field. The problem arises when characters are deleted, as the array does not update in real-time and remains the same as the last search query. I suspect this is happening be ...

JQuery Form Validation - Detecting Input Changes

Currently, I have a form set up with jQuery validation that works well, but I want to enhance its functionality. The form uses a plugin for validation, but it only checks for errors upon submission. I'm interested in finding a way to validate the fiel ...

Fetching dynamic data using AJAX in Laravel

Working on creating a finder with advanced search capabilities, I've made progress but now facing an issue with retrieving the third part of my search query. Approach Select a category Select a subcategory Select specifications of products in the s ...

Is there a way to share another person's contact card using whatsapp-web.js?

Is it possible to send a contact card of someone else using whatsapp-web.js, even if the person is not saved in my phone's contact list? I want to send a contact card to someone who is on my phone's contacts, but the contact information I want to ...

Use the reduce method to convert a JavaScript object from 2 to 1

Looking to create a function that can transform these objects: const input1 = [ { id: "lkhj68C13h8uWh4RJz7", post: "on XSS attacks", gender: "Littérature", postId: "cxTbP5EZjNCxw7rD60L7", }, { ...

Retrieving data from a remote PHP server using JavaScript

I am currently working on two separate websites. Site A is coded using only HTML and JavaScript, while site B utilizes PHP. I am trying to figure out a way to access variables from site B within site A. For example: The code for site A looks something li ...

Vue fails to reflect changes in data when it is updated

I have a page where I can access data by calling domain.com/subpage?soundfile=something Using the fetch method, I extract the query parameter from the URL to retrieve the necessary information. The retrieval process is successful as indicated by the data ...

Apollo GraphQL request contains a variable with a serialized UTC date that is not properly formatted for the GMT+3 timezone

When passing a UTC Date object to an Apollo GraphQL mutation, the serialized variable in the request payload displays an incorrect datetime. Within my React component (in a GMT+3 timezone), I am converting the local datetime startDateTime to UTC: // Local ...

Ways to merge two arrays into one in React JS

Here are two arrays presented below: const arrayA = { 0: { id: XXXXXXX, name: "test" }, 1: { id: YYYYYYY, name: "example" } } const arrayB = { 0: { id: XXXXXXX, category: "sea", } 1: { id: YYYYY ...

Several directories for viewing in Node.js with Express

I have been researching different solutions, but I am still unsure about how to effectively integrate Express with multiple view folders. Imagine an Express application divided into distinct parts, each organized in its own subfolder: app +partA + ...

Tips for sending data from an HTML page to an Angular custom element

I have successfully created an angular custom element from an angular component that I would like to call from a standard HTML page. The custom element requires a parameter, which functions properly when called as a component within an angular project. Ho ...

Employing featherlightGallery.js without the need for anchor tags

I've been experimenting with the FeatherlightGallery plugin for a lightboxing feature on an image slider. The slider contains images directly, without anchor tags wrapping them. However, I'm facing an issue where clicking next/prev doesn't l ...

Using JavaScript in PHP files to create a box shadow effect while scrolling may not produce the desired result

Issue at hand : My JavaScript is not functioning properly in my .php files CSS not applying while scrolling *CSS Files are named "var.css" #kepala { padding: 10px; top: 0px; left: 0px; right: 0px; position: fixed; background - c ...

Is there a way to automatically fill in a MUI textfield in a React Hook form with data retrieved from Firestore?

Utilizing React Hook Forms alongside MUI TextField components has been a productive challenge for me. I've been able to successfully fetch data from Firestore and aim to prefill the form with this retrieved information. Although I am employing useFor ...

What is the best way to run a lengthy task in Node.js by periodically checking the database for updates?

In my current setup, there is a routine that continuously checks the database for any pending work orders. Upon finding one, it needs to execute it promptly. The system can handle only one work order at a time, and these tasks may vary in duration from 5 s ...

Locate data objects using JavaScript keys

My object looks like this: { sunday: {status: "open", opening_time: "11:30 am", closing_time: "12:00 pm"}, monday: {status: "close", opening_time: "", closing_time: ""}, tuesday: {status: "close", opening_time: "", closing_time: ""}, wednesday: {st ...

Learn how to incorporate an image into your Codepen project using Dropbox and Javascript, along with a step-by-step guide on having the picture's name announced when shown on the screen

Hey there, I'm in need of some assistance. I have a Codepen page where I am working on displaying 4 random shapes (Square, Triangle, Circle, and Cross) one at a time, with the computer speaking the name of each shape when clicked. I want to pull these ...

React Apollo Error - When using refetchQueries, data does not re-render in one component but does so in another. Surprisingly, it works when the refetchQueries is in the same

Within my application, there is a Main Component that displays a list of todos. Additionally, the Sidebar Component showcases various products as illustrated below ...

Can you explain the significance of Angular 2 hashtags within a template?

Currently exploring Angular 2 and stumbled upon the following code: <input #searchBox (keyup)="search(searchBox.value)" Surprisingly, it works! Despite its functionality, the significance of #searchBox eludes me. Extensive research in the documentati ...

Looking for guidance on implementing throttle with the .hover() function in jQuery?

Seeking a way to efficiently throttle a hover function using jQuery. Despite various examples, none seem to work as intended. The use of $.throttle doesn't throw errors but ends up halting the animation completely. Here is the code snippet in question ...