0
The date that comes from SQL SERVER comes in the format like this: 20181212. I tried to format, but it only works if it comes in 2018-12-12 format.
I place this date inside a table by API I pull where ta data (date comes from 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}`);
}
There 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>
Only it only comes in the format it gives in the SQL SERVER dataset: 20181212.
I got this shape ready:
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 keeps coming 2018/12/12
Stay 2018-01-23 and not dd-mm-yyyy
– Maria
Just change places, it was just an example, I’ll change you to see
– Lucas