Format a table’s value

Asked

Viewed 72 times

-5

I have a table that I receive date data in this format: -'06/05/2019 09:07:34 and -'06/05/2019 always with these characters -'.

I would like to format the values of the date columns to 06/05/2019 09:07:34 and 06/05/2019.

        tbody {
            font-size: 11px;
            color: #bdbdbd;

        }

        input {
            color: #bdbdbd;
        }

        th {
            color: #bdbdbd;

        }


        table.striped>tbody>tr:nth-child(odd) {

            background-color: #293a46;

        }

        body {
            background: url(http://seac-pr.com.br/content/uploads/2014/05/INTERSEP.png) #1a2224;
            background-repeat: no-repeat;
        }



        .input-field input[type=text]:focus+label,
        .materialize-textarea:focus:not([readonly])+label {
            color: #b7c3d0 !important;
        }


        .input-field input[type=text]:focus,
        .materialize-textarea:focus:not([readonly]) {
            border-bottom: 1px solid #b7c3d0 !important;
            box-shadow: 0 1px 0 0 #b7c3d0 !important;
        }

        .blackIcon {
            color: #000;
        }

        .greenIcon {
            color: green;
        }

        .rBlueIcon {
            color: royalblue;
        }

        table {
            border-collapse: collapse;
            border: 1px solid #A4A4A4;
        }

        table td {
            border: 1px solid #A4A4A4;
        }

        table.highlight>tbody>tr:hover {
            background-color: #2E5C78;
        }

        table.highlight>tbody>tr {
            color: white;
        }
<html>

<head>
    <script src="//www.google.com/jsapi"></script>
  
    <base target="_top">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
   
</head>

<body>

            <table class="highlight">
                <thead>

                    <tr>
                        <th>ID REGISTRO</th>
                        <th>Data e hora do Registro</th>
                        <th>Data da falta</th>
    
                    </tr>
                </thead>

                <tbody id="coportoTabela">

                    <tr>
                        <td>COD1557144453513</td>
                        <td>-'06/05/2019 09:07:34</td>
                        <td>-'06/05/2019</td>
                        
                    </tr>
                    <tr>
                        <td>COD1557148342924</td>
                        <td>-'06/05/2019 10:12:23</td>
                        <td>-'06/05/2019</td>
                        
                    </tr>
                </tbody>
            </table>



        </div>
    </div>

</body>

</html>

  • 1

    Please show us the javascript code.

  • 1

    Where does this data come from??? I think it is necessary to see the backend to try to solve the problem.

1 answer

1

You can try:

    function formatDate(date) {
        var d = new Date(date),
day = '' + d.getDate(),
            month = '' + (d.getMonth() + 1),

            year = d.getFullYear();

        if (month.length < 2) 
            month = '0' + month;
        if (day.length < 2) 
            day = '0' + day;

        return [day, month, year].join('-');
    }

Example of use:

alert(formatDate('Sun Fev 20,2020'));

Rsultado:

20-02-2020

But ideally you show your Javascript.

  • i was able to remove the first two characters using " . Slice(2) " within the date array

Browser other questions tagged

You are not signed in. Login or sign up in order to post.