Greetings to all who are perusing this message.
I have devised a technique for retrieving today's date along with the current time. If the deadline value in the database is null, it will fetch the current datetime and format it correctly. Otherwise, it will simply format the deadline.
However, I am curious if there exists a simpler way to accomplish this?
getFormattedDateTime(deadline){
var formattedDateTime;
if(deadline == null){
var currentDate = new Date();
var month = ('0' + (currentDate.getMonth() + 1)).slice(-2);
var day = ('0' + currentDate.getDate()).slice(-2);
var year = currentDate.getFullYear();
var hour = ('0' + currentDate.getHours()).slice(-2);
var minute = ('0' + currentDate.getMinutes()).slice(-2);
var formattedDate = year + '-' + month + '-' + day + 'T' + hour + ':' + minute;
formattedDateTime = moment(formattedDate, 'YYYY-MM-DD HH:mm').format('YYYY-MM-DDTHH:mm');
} else {
formattedDateTime = moment(deadline, 'YYYY-MM-DD HH:mm').format('YYYY-MM-DDTHH:mm');
};
return formattedDateTime;
}