Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Conversion of a simple Month Year string to short form

An Illustration

> function getDateShortName(s, shortYear=true) {
...     let parts = s.split(/\s+/ig)
...     
...     if(shortYear) {
.....         return parts[0].slice(0, 3) + '\'' + parts[1].slice(2)
.....     } else {
.....         return parts[0].slice(0, 3) + '\'' + parts[1]
.....     }
... }
undefined
> 
> getDateShortName("January 2020")
"Jan'20"
> 
> getDateShortName("January 2020", false)
"Jan'2020"
> 
> getDateShortName("February  2021")
"Feb'21"
> 
> getDateShortName("February  2021", false)
"Feb'2021"
> 
> getDateShortName("February  2021", true)
"Feb'21"
> 
> 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.