Question: Anyone can help me with the "replace" function in Javascript? I'm trying to get only the date of an automatic text box where's showing the date & time:

In the text box I have: **24-Jun-2016 06:00:00 PM**
And I only need the date "**24-Jun-2016**"

I used the replace function in others text boxes and worked! but I'm complete loss of to use it to get only the date!:

I tried this but it's showing nothing:

```
var nrd=document.getElementById('nextResponse').value;

```

`nrd=nrd.replace('00:00:00', '')`;

```
nrd=nrd.replace('PM', '');

```

Any help will be appreciate it!

Answer: 
Using the `replace` method

```js
var dateTime = "24-Jun-2016 06:00:00 PM";
var displayDate = document.getElementById("display-date");
var date = dateTime.replace(/[0-9]{2}:[0-9]{2}:[0-9]{2}\s[A|P]M/, '');

displayDate.innerHTML = date;
```

```html
<p id="display-date"></p>
```

The best method would probably be using the `split` function. We have a datetime value and we want to extract just the date part, the portion that is directly before the space.

```js
var dateTime = "24-Jun-2016 06:00:00 PM ";
var dateDisplay = document.getElementById("date-display");

var date = dateTime.split(/\s/)[0];
dateDisplay.innerHTML = date;
```

```html
<p id="date-display"></p>
```
var a = "24-Jun-2016 06:00:00 PM";

`console.log(a.split(" ")[0]);` gives `24-Jun-2016`