-1
                    //condition if status is shown as active or inactive
                    function getshiftstatus(start_datetime, end_datetime) {
                        var s_status = '';
                        if (start_datetime === null) {
                            s_status = '<p class="text-danger font-weight-bold">Inactive</p>';
                        } else if (end_datetime === null) {
                            s_status = '<p class="text-success font-weight-bold">Active</p>';
                        }  else {
                            s_status = `<table>
                                          <tr class="row-gray">
                                            <td class="p-0 font-weight-bold">From:</td>
                                            <td class="tb-schedule">${start_datetime}</td>
                                          </tr><tr class="row-gray">
                                            <td class="p-0 font-weight-bold">To:</td>
                                            <td class="tb-schedule">${end_datetime}</td>
                                          </tr>
                                        </table>`;
                        }
                        return s_status;
                    }

These two functions: ${start_datetime} and ${end_datetime} output a date with time, but in my case I just want to show the date only how do I format my code to do this?

1

Like in the screenshot, I am aiming for the same output without the 24 hour time

Here are the SQL columns:

2

1 Answers1

0

If you are certain the date will always be separated with an empty space then you should split the string and get the first half that contains the date.

const dateTime = '2021-08-13 01:19:26';

const getDate = dateTime => {
  const [date] = dateTime.split(' ')
  return date
}

console.log(getDate(dateTime))
Emiel Zuurbier
  • 19,095
  • 3
  • 17
  • 32
  • 1
    The first example produces "NaN-NaN-NaN" in Safari, see [*Why does Date.parse give incorrect results?*](https://stackoverflow.com/questions/2587345/why-does-date-parse-give-incorrect-results) – RobG Aug 16 '21 at 12:43
  • @RobG can't wait for the Temporal API. – Emiel Zuurbier Aug 16 '21 at 13:16
  • I don't understand the need for the Temporal API. Surely *Date.parse* and *toString* could have just been extended to accept format tokens? Then later to accept an IANA location for parsing and formatting, and extend the Date object to add IANA location to use for non–UTC methods instead of system settings. That would pretty much do it for me. – RobG Aug 17 '21 at 03:33