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
MarkBoots3y ago
how did you get month? take a look at the Date object on mdn
CDL
CDLOP3y 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
MarkBoots3y ago
what do you use to get the 03? Because if you do date.getDate() you should get a number
Joao
Joao3y ago
oops, my bad thought I read how to add not remove 😅
MarkBoots
MarkBoots3y ago
it happens
Joao
Joao3y 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
MarkBoots3y 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
CDLOP3y 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
CDLOP3y ago
Thanks haha
Joao
Joao3y ago
Using the new Intl API, fancy 😎 I still need to look into it
MarkBoots
MarkBoots3y ago
i was hoping to get more options for custom formatting (declare a pattern or something, but that's not a thing yet)
CDL
CDLOP3y 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
MarkBoots3y ago
nothing is waisted. you learned on the way
CDL
CDLOP3y ago
Oh for sure I really enjoyed that learning experience Thanks a lot for the help
MarkBoots
MarkBoots3y ago
no problem, good luck!
Want results from more Discord servers?
Add your server