-2

I'm new to angular and facing one issue I've date

const joiningDate = Aug 7, 2023
O/P - 7-Aug-2023 

and I want to convert such date format to the above one, not sure how we can do it, Do we we have any inbuilt pipes to format such date or we need to use native JS to do it?

Kriti
  • 9
  • 3
  • 1
    `const joiningDate = Aug 7, 2023` is invalid. – phuzi Aug 07 '23 at 07:45
  • @phuzi we get such date format from API, can't help it, we just need to somehow modify it – Kriti Aug 07 '23 at 07:46
  • Welcome to Stack Overflow. This is a very common task in Angular, and there are tons of resources on how to achieve it. There is no need to ask a new question here. Please review: [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/q/261592/5470544) – JSON Derulo Aug 07 '23 at 07:48
  • Did you mean `const joiningDate = "Aug 7, 2023"` then? If so, you're going to need to parse the string to a valid date first. Angular pipeline should then be able to format the date anyway you like. If not, do you already have a JS/TS date? – phuzi Aug 07 '23 at 07:48
  • @phuzi ohh yes we get the string – Kriti Aug 07 '23 at 07:50
  • @phuzi no need to parse the string, we can directly use the inbuild angular date pipe `const newDate = this.datePipe.transform(joiningDate , 'd-MMM-y');` – Kriti Aug 07 '23 at 08:52
  • @Kriti - Can you confirm that it can parse this date string `Aug 7, 2023` without any additional code/transform? – phuzi Aug 07 '23 at 09:25

0 Answers0