I need to concatenate a date value and time value to make one value representing a datetime.

asher14
Tera Contributor

The name on the table that holds the value for date&time is called 'u_arrival_date'.  I want to combine both separate values to one inside of 'u_arrival_date'.

I wrote a script to get the values input. However, I only need date format for date (eg. 02/22/2023) and I only need time format for time (eg. 10:00:00). Currently arrivalDate and arrivalTime are showing the long values and I just need partial like the examples above. 

 

How do I parse the values for arrivalDate and arrivalTime?

How can I set the value of dateTime which should be the parsed output to the record on the table 'u_arrival_date'?

 

 

function combineDateWithTime(d,t){

  return new Date(

  d.getFullYear(),

  d.getMonth(),

  d.getDate(),

  t.getHours(),

  t.getMinutes()

}

var arrivalDate = c.checkin.u_arrival_date;

var arrivalTime = c.checkin.arrival_time;

var dateTime = combinedDateWithTime(arrivalDate, arrivalTime);

c.checkin.u_arrival_date = combinedDateWithTime(arrivalDate, arrivalTime);

 

For reference :

u_arrival_date - field name on table

c.checkin.u_arrival_date - ng-model in HTML

c.checkin.arrival_time - ng-model in HTML

u_arrival_date - is called in my angualr provider on the widget

 

Output should be:

Example (02/25/2023 12:30:00)

2 REPLIES 2

Claude DAmico
Kilo Sage

I played with this a little. Try this.

 

//May need to add .toString() to the end of these first two c.checkin values
var arrivalDate = new Date(c.checkin.u_arrival_date);
var arrivalTime = new Date("01/01/1980 " + c.checkin.arrival_time); //The "date" here does not matter since we are going to pull only the time from it anyway

var dateTime = arrivalDate.getMonth() + "/" + arrivalDate.getDate() + "/" + arrivalDate.getFullYear() + " " + arrivalTime.getHours() + ":" + arrivalTime.getMinutes + ":00";

c.checkin.u_arrival_date = dateTime;

 

Claude E. D'Amico, III - CSA

I will give this a try and let you know if this worked. Thanks!