Hello
Currently we are using javascript: js: (new Date().getFullYear() + '.'+(new Date().getMonth()+1)) to fetch time period as on date. Eg. above script helps in fetching 2020.11
Now if we want to fetch Jan/Feb/March data then I will 0 appended to it eg. 2021.01/2021.02/2021.03 so is there a way to fetch this dynamically i.e if month length is 1 then append 0 ahead of it and if the months are Oct/Nov/Dec then 0 need not be appended ahead of them. Is there a way to include this if-else in BPC conversion file javascript ?
Regards
Neha
Request clarification before answering.
Easy:
new Date().getFullYear() + '.'+('0'+(new Date().getMonth()+1)).substr(-2, 2)Standard way...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
nehayadav0911
Sorry, but why not to test the code in any online JavaScript testing tool???
For example: https://js.do
substr(-2,2)-2 - means 2 positions from the end of the string
2 - 2 characters
P.S. Javascript:
('0'+(new Date().getMonth()+1)).substr(-2, 2)Is equivalent of Excel formula:
=RIGHT("0"&MONTH(NOW())+1;2)
| User | Count |
|---|---|
| 7 | |
| 3 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.