The date that comes from SQL SERVER comes in the following format: 20181212. I tried formatting, but it only works if it comes in the 2018-12-12 format.
I put this date inside a table by the API I pull where the data is (date comes from the API).
function Progress() {
fetch('http://API_AQUI', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: 'L2_PRODUTO=${id}'
}).then(response => response.json().then(data => ({
data: data,
status: response.status
})
).then(res => {
res.data.map(element => {
$('.progresso-1').append('${element.DATAUM}');
$('.progresso-2').append('${element.DATADOIS}');
}
Then on the front I put:
<tr>
<td class="td-b">Data Um</td>
<td class="progresso-1"></td>
</tr>
<tr>
<td class="td-b">Data Dois</td>
<td class="progresso-2"></td>
</tr>
It only comes in the format that it gives in the SQL SERVER database: 20181212.
I have this ready form:
function formatarData(str){
return [str.slice(0, 4), str.slice(4, 6), str.slice(-2)].join('/'); // para formato yyyy-mm-dd
// ou para retornar um objeto Date
return new Date(str.slice(0, 4), Number(str.slice(4, 6)) + 1, str.slice(-2));
}
function formatDate(str)
{
return str.split('/').reverse().join('/');
}
But it's coming 2018/12/12