JSFiddle - React, Tailwind, and code Playground

by ecropolis

HTML

<script src="https://ecropolis.s3.amazonaws.com/ui/libs/moment.min.js"></script>
<div id="out">

</div>

JavaScript

s = 'I love living "in" the city';
s = "I love living 'in' the city";
s = "I love living in the city";
mydate = '1970-JAN-31';
mydate = '1970-01-31';

deeb = dateConv(mydate);
yo = addslashes(s);
//$('#out').html(yo);
$('#out').html(deeb);

function addslashes( str ) {
    return (str + '').replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');
}


function dateConv(d){
		if(d.toUpperCase() === 'NULL')
    		return 'NULL';
		monthNames: ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"];
		var ds = d.replace(/\'/g, "").trim().split('-');
    var month = ds[1];
    if(isNaN(month)){
    		var month = (monthNames.indexOf(ds[1].toUpperCase())) + 1;
    }
    month = ('0'+(month)).slice(-2);
    var test = new Date(ds[0], month, ds[2]);
    var value = (ds !== 'NULL' ? new Date(ds)) : ds;
    if (test === 'Invalid Date'){
    		return 'Invalid Date';
    } 
    return value.format('YYYY-MMM-DD').toString().toUpperCase();
    
}