Question: The problem is, right now, as a result of function I am getting this on.

```
"\n    inventory:\n-devices:\n      platformtypes:\n    "

```

But my purpose is to get

```
 "inventory:\n-devices:\n platformtypes:"

```

This is what I am doing,

```
function searchStringInText(text, str) {
    for (let i = 0; i < text.split("\n").length; i++) {
      for (let j = 0; j < text.split("\n").length; j++) {
        if (text.split("\n")[j].includes(str)) {
          return (
            [text.split("\n")[j],
            text.split("\n")[j + 1],
            text.split("\n")[j + 2]].join("\n"));
        }
      }
    }
  }

```

So, basically, all i need is by calling searchStringInText(text, "lesson") to get from this text

```
const text ="explore: true
moon: -932373914.9990492
pot: -505393312.24021673
lesson: true
cut:
  - next
  - - false
    - white
    - true
    - true
    - 1835506785
    - false
  - -1526841500
  - 1191695591.8601308
  - 2062118801.9208922
  - title
shorter: out"

```

I need to get

const newText=

```
lesson: true
        cut:
          - next

```

So, there is a need to return new text started from a founded occurence, and including next 2 lines.

Answer: 
Assuming your dates are in the ISO format and need another ISO date string as the result:

```js
function start (date, time) {
    return `${date.split("T")[0]}T${time.split("T")[1]}`;
}

console.log(start("2021-05-25T09:50:40.603Z", "2021-05-12T11:52:40.603Z"));
```

In the ISO format, the date is separated from the time using the letter `T` (for "time"). My function splits both dates at that point. For the date, we use `[0]` (before T) and the time is `[1]` (after the T). The `Z` (Zulu) at the end stands for Zulu Time which is the same as UTC. More about this format on [Wikipedia](https://en.wikipedia.org/wiki/ISO_8601).

When storing dates and times in JavaScript, I would highly recommend using UNIX timestamps, which is a number representing the milliseconds past after the beginning of the UNIX epoch (Jan 1 1970). These timestamps can easily be converted to date objects in most programming languages and platforms. Here is the same function, but using UNIX timestamps and the JavaScript date object.

```js
function start (date, time) {
  return new Date(`${new Date(date).toDateString()} ${new Date(time).toTimeString()}`)
}

console.log(start(1621936240603, 1620820360603));
// this function will also recognise strings
console.log(start("25 May 2020", "Feb 13 2019 9:00 AM UTC"));
```
You can just use the Date object:

```js
const target = new Date("2021-05-25T09:50:40.603Z")
const startTime = new Date("2021-05-12T11:52:40.603Z")

target.setHours(startTime.getHours())
target.setMinutes(startTime.getMinutes())
target.setSeconds(startTime.getSeconds())
target.setMilliseconds(startTime.getMilliseconds())
console.log(target)
```

Or by manupulating the strings, you can do it so:

```
const startDate = "2021-05-25T09:50:40.603Z";
const startTime = "2021-05-12T11:52:40.603Z";
console.log(`${startDate.substr(0,11)}${startTime.substr(11)}`)

```