-1

I have CSV with dates in format DD-MM-YYYY but sometimes I work in Excel and it changes the dates to format DD/MM/YYYY

Code example

var dateParts = value['TAX_CALCULATION_DATE'].split("/"); //id date has "-" or "/"
var dateObject = new Date(+dateParts[2], dateParts[1] - 1, +dateParts[0]);
firestoreObject.TAX_CALCULATION_DATE = firebase.firestore.Timestamp.fromDate(dateObject);

How to include "/" and "-" in one split?

awariat
  • 331
  • 1
  • 5
  • 22
  • [How do I split a string with multiple separators in javascript?](https://stackoverflow.com/q/650022) – palaѕн Jun 17 '20 at 11:39

1 Answers1

1

You can use regex in split;

// Matches / or -
const regex = /\/|-/g;
yourDate.split(regex);
Reyno
  • 6,119
  • 18
  • 27