adding the day name to date?

https://codepen.io/Laing91/pen/vYrGQWK Without giving me the actual answer, how would I go about removing the leading zero from the days “01, 02, 03 etc…? I’ve read up on .replace and parseInt but couldn’t quite work out how to implement either into my current code..
16 Replies
MarkBoots
MarkBoots2y ago
how did you get month? take a look at the Date object on mdn
CDL
CDL2y ago
Hahaha I’m so silly.. thanks 🙂 New issue: how to remove the 0 from 01, 02 etc…I’ve read up on parseInt and also .replace but not sure which one works for my current code as I did try to implement both with not much luck.. I’m wanting to change it so it reads “Thursday, 3rd” basically. I know how to add the st, th, rd, just need to remove the leading zero.
MarkBoots
MarkBoots2y ago
what do you use to get the 03? Because if you do date.getDate() you should get a number
Joao
Joao2y ago
oops, my bad thought I read how to add not remove 😅
MarkBoots
MarkBoots2y ago
it happens
Joao
Joao2y ago
If you still want to use your own method instead of relying on MarkBoots solution, you can use .replace() providing a regular expression. You can use this to detect leading zeroes in front of single digits.
MarkBoots
MarkBoots2y ago
here my a way how you could do it without a lookup table for month names / weekday names (only look if you want, otherwise just ignore) https://codepen.io/MarkBoots/pen/ExRKMMY?editors=1011
CDL
CDL2y ago
Sorry I was tweaking my code and ended up replacing the old one and couldn’t get it back hahahaha That’s exactly what I was looking for, thanks 🙂 Https://Codepen.io/Laing91/pen/jOkqRPX
CDL
CDL2y ago
Thanks haha
Joao
Joao2y ago
Using the new Intl API, fancy 😎 I still need to look into it
MarkBoots
MarkBoots2y ago
i was hoping to get more options for custom formatting (declare a pattern or something, but that's not a thing yet)
CDL
CDL2y ago
I haven’t seen that concept, it’s pretty cool. I just wish I had my original attempt at this saved so I could show my mentor my first go then my refined go lol
MarkBoots
MarkBoots2y ago
nothing is waisted. you learned on the way
CDL
CDL2y ago
Oh for sure I really enjoyed that learning experience Thanks a lot for the help
MarkBoots
MarkBoots2y ago
no problem, good luck!
Want results from more Discord servers?
Add your server