I’ve a date like that 01/03/22 22:09 and I want to store it in DB just in a format of date like like that '2022-03-01'; I’ve tried Regex but still get time in an hour:minute too
How can I delete it?
const date_time = '22/01/03 22:09';
const only_date = date_time.replace(/(\d{2})\/(\d{2})\/(\d{2})/,"'20$3-$2-$1'");
//console.log(only_date.substring(0,only_date.lastIndexOf("'")+1))
console.log(only_date)
PS: without using substring or slice… just with regex is there a way to do that?
>Solution :
You missed the .*
const date_time = '22/01/03 22:09';
const only_date = date_time.replace(/(\d{2})\/(\d{2})\/(\d{2}).*/,"'20$3-$2-$1'");
console.log(only_date)