How to Extract Months from dates contains in a html table column?
I have a html table. One column contains date values. I want to extract month
of those dates
and print it in the console. Date format is yyyy-MM-dd. Here is my code:
var myTable = document.getElementById('openDispatchNoteTable');
for (var i = 0 ; i < myTable.rows.length ; i++) {
console.log("date : " + myTable.rows[i].cells[6].innerText);
}
myTable.rows[i].cells[6].innerText
gives 2018-November-14
as the output.
Can you please help me to solve this problem?
javascript html
add a comment |
I have a html table. One column contains date values. I want to extract month
of those dates
and print it in the console. Date format is yyyy-MM-dd. Here is my code:
var myTable = document.getElementById('openDispatchNoteTable');
for (var i = 0 ; i < myTable.rows.length ; i++) {
console.log("date : " + myTable.rows[i].cells[6].innerText);
}
myTable.rows[i].cells[6].innerText
gives 2018-November-14
as the output.
Can you please help me to solve this problem?
javascript html
add a comment |
I have a html table. One column contains date values. I want to extract month
of those dates
and print it in the console. Date format is yyyy-MM-dd. Here is my code:
var myTable = document.getElementById('openDispatchNoteTable');
for (var i = 0 ; i < myTable.rows.length ; i++) {
console.log("date : " + myTable.rows[i].cells[6].innerText);
}
myTable.rows[i].cells[6].innerText
gives 2018-November-14
as the output.
Can you please help me to solve this problem?
javascript html
I have a html table. One column contains date values. I want to extract month
of those dates
and print it in the console. Date format is yyyy-MM-dd. Here is my code:
var myTable = document.getElementById('openDispatchNoteTable');
for (var i = 0 ; i < myTable.rows.length ; i++) {
console.log("date : " + myTable.rows[i].cells[6].innerText);
}
myTable.rows[i].cells[6].innerText
gives 2018-November-14
as the output.
Can you please help me to solve this problem?
javascript html
javascript html
edited Nov 21 '18 at 3:00
asked Nov 20 '18 at 10:55
Ravindu Saluwadana
117
117
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
if format is the same in all of outputs - then use regexp .innerText.match(/[a-z]+/i)[0]
console.log(document.querySelector('div').innerText.match(/[a-z]+/i)[0])
<div>2018-November-14</div>
Also i found good internationalized solution here: get month name from date Second best answer uses toLocaleString
.
Thank you very much for your answer. This worked for me.
– Ravindu Saluwadana
Nov 20 '18 at 11:09
add a comment |
In your case you can use the replace() method of Javascript.
Use this replace(/[^a-zA-Z ]/g, "")
regex which will replace everything with "" other then characters.
var myTable = document.getElementById("myTable");
for (var i = 1; i < myTable.rows.length; i++) {
console.log("Actual Date : " + myTable.rows[i].cells[0].innerText);
console.log("Only Month : " + myTable.rows[i].cells[0].innerText.replace(/[^a-zA-Z ]/g, ""));
}
<table id="myTable" border='1'>
<tr>
<th>Date</th>
</tr>
<tr>
<td>
28-November-2018
</td>
</tr>
<tr>
<td>
29-November-2018
</td>
</tr>
<tr>
<td>
30-November-2018
</td>
</tr>
</table>
add a comment |
I highly recommend using momentJS. It has a very elaborate API to handle things just like your need. In this case, the moment object can get the date in your format and then you can use the month
function to extract the month.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391453%2fhow-to-extract-months-from-dates-contains-in-a-html-table-column%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
if format is the same in all of outputs - then use regexp .innerText.match(/[a-z]+/i)[0]
console.log(document.querySelector('div').innerText.match(/[a-z]+/i)[0])
<div>2018-November-14</div>
Also i found good internationalized solution here: get month name from date Second best answer uses toLocaleString
.
Thank you very much for your answer. This worked for me.
– Ravindu Saluwadana
Nov 20 '18 at 11:09
add a comment |
if format is the same in all of outputs - then use regexp .innerText.match(/[a-z]+/i)[0]
console.log(document.querySelector('div').innerText.match(/[a-z]+/i)[0])
<div>2018-November-14</div>
Also i found good internationalized solution here: get month name from date Second best answer uses toLocaleString
.
Thank you very much for your answer. This worked for me.
– Ravindu Saluwadana
Nov 20 '18 at 11:09
add a comment |
if format is the same in all of outputs - then use regexp .innerText.match(/[a-z]+/i)[0]
console.log(document.querySelector('div').innerText.match(/[a-z]+/i)[0])
<div>2018-November-14</div>
Also i found good internationalized solution here: get month name from date Second best answer uses toLocaleString
.
if format is the same in all of outputs - then use regexp .innerText.match(/[a-z]+/i)[0]
console.log(document.querySelector('div').innerText.match(/[a-z]+/i)[0])
<div>2018-November-14</div>
Also i found good internationalized solution here: get month name from date Second best answer uses toLocaleString
.
console.log(document.querySelector('div').innerText.match(/[a-z]+/i)[0])
<div>2018-November-14</div>
console.log(document.querySelector('div').innerText.match(/[a-z]+/i)[0])
<div>2018-November-14</div>
edited Nov 20 '18 at 11:10
answered Nov 20 '18 at 11:01
Smollet777
1,3611015
1,3611015
Thank you very much for your answer. This worked for me.
– Ravindu Saluwadana
Nov 20 '18 at 11:09
add a comment |
Thank you very much for your answer. This worked for me.
– Ravindu Saluwadana
Nov 20 '18 at 11:09
Thank you very much for your answer. This worked for me.
– Ravindu Saluwadana
Nov 20 '18 at 11:09
Thank you very much for your answer. This worked for me.
– Ravindu Saluwadana
Nov 20 '18 at 11:09
add a comment |
In your case you can use the replace() method of Javascript.
Use this replace(/[^a-zA-Z ]/g, "")
regex which will replace everything with "" other then characters.
var myTable = document.getElementById("myTable");
for (var i = 1; i < myTable.rows.length; i++) {
console.log("Actual Date : " + myTable.rows[i].cells[0].innerText);
console.log("Only Month : " + myTable.rows[i].cells[0].innerText.replace(/[^a-zA-Z ]/g, ""));
}
<table id="myTable" border='1'>
<tr>
<th>Date</th>
</tr>
<tr>
<td>
28-November-2018
</td>
</tr>
<tr>
<td>
29-November-2018
</td>
</tr>
<tr>
<td>
30-November-2018
</td>
</tr>
</table>
add a comment |
In your case you can use the replace() method of Javascript.
Use this replace(/[^a-zA-Z ]/g, "")
regex which will replace everything with "" other then characters.
var myTable = document.getElementById("myTable");
for (var i = 1; i < myTable.rows.length; i++) {
console.log("Actual Date : " + myTable.rows[i].cells[0].innerText);
console.log("Only Month : " + myTable.rows[i].cells[0].innerText.replace(/[^a-zA-Z ]/g, ""));
}
<table id="myTable" border='1'>
<tr>
<th>Date</th>
</tr>
<tr>
<td>
28-November-2018
</td>
</tr>
<tr>
<td>
29-November-2018
</td>
</tr>
<tr>
<td>
30-November-2018
</td>
</tr>
</table>
add a comment |
In your case you can use the replace() method of Javascript.
Use this replace(/[^a-zA-Z ]/g, "")
regex which will replace everything with "" other then characters.
var myTable = document.getElementById("myTable");
for (var i = 1; i < myTable.rows.length; i++) {
console.log("Actual Date : " + myTable.rows[i].cells[0].innerText);
console.log("Only Month : " + myTable.rows[i].cells[0].innerText.replace(/[^a-zA-Z ]/g, ""));
}
<table id="myTable" border='1'>
<tr>
<th>Date</th>
</tr>
<tr>
<td>
28-November-2018
</td>
</tr>
<tr>
<td>
29-November-2018
</td>
</tr>
<tr>
<td>
30-November-2018
</td>
</tr>
</table>
In your case you can use the replace() method of Javascript.
Use this replace(/[^a-zA-Z ]/g, "")
regex which will replace everything with "" other then characters.
var myTable = document.getElementById("myTable");
for (var i = 1; i < myTable.rows.length; i++) {
console.log("Actual Date : " + myTable.rows[i].cells[0].innerText);
console.log("Only Month : " + myTable.rows[i].cells[0].innerText.replace(/[^a-zA-Z ]/g, ""));
}
<table id="myTable" border='1'>
<tr>
<th>Date</th>
</tr>
<tr>
<td>
28-November-2018
</td>
</tr>
<tr>
<td>
29-November-2018
</td>
</tr>
<tr>
<td>
30-November-2018
</td>
</tr>
</table>
var myTable = document.getElementById("myTable");
for (var i = 1; i < myTable.rows.length; i++) {
console.log("Actual Date : " + myTable.rows[i].cells[0].innerText);
console.log("Only Month : " + myTable.rows[i].cells[0].innerText.replace(/[^a-zA-Z ]/g, ""));
}
<table id="myTable" border='1'>
<tr>
<th>Date</th>
</tr>
<tr>
<td>
28-November-2018
</td>
</tr>
<tr>
<td>
29-November-2018
</td>
</tr>
<tr>
<td>
30-November-2018
</td>
</tr>
</table>
var myTable = document.getElementById("myTable");
for (var i = 1; i < myTable.rows.length; i++) {
console.log("Actual Date : " + myTable.rows[i].cells[0].innerText);
console.log("Only Month : " + myTable.rows[i].cells[0].innerText.replace(/[^a-zA-Z ]/g, ""));
}
<table id="myTable" border='1'>
<tr>
<th>Date</th>
</tr>
<tr>
<td>
28-November-2018
</td>
</tr>
<tr>
<td>
29-November-2018
</td>
</tr>
<tr>
<td>
30-November-2018
</td>
</tr>
</table>
edited Nov 20 '18 at 11:21
Smollet777
1,3611015
1,3611015
answered Nov 20 '18 at 11:16
Mohan Rajput
271212
271212
add a comment |
add a comment |
I highly recommend using momentJS. It has a very elaborate API to handle things just like your need. In this case, the moment object can get the date in your format and then you can use the month
function to extract the month.
add a comment |
I highly recommend using momentJS. It has a very elaborate API to handle things just like your need. In this case, the moment object can get the date in your format and then you can use the month
function to extract the month.
add a comment |
I highly recommend using momentJS. It has a very elaborate API to handle things just like your need. In this case, the moment object can get the date in your format and then you can use the month
function to extract the month.
I highly recommend using momentJS. It has a very elaborate API to handle things just like your need. In this case, the moment object can get the date in your format and then you can use the month
function to extract the month.
answered Nov 20 '18 at 11:01
Gilad Bar
633314
633314
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391453%2fhow-to-extract-months-from-dates-contains-in-a-html-table-column%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown