admin管理员组文章数量:1327849
in database the created date is like "2018-12-01 18:51:41".Based on this date i want to pare this date with current month.If current month is not equal to created date just show alert "not in this month".
I tried this code so far
const dateTime = "2018-09-01 18:51:41";
const parts = dateTime.split(/[- :]/);
var month = parts[1];
var day = parts[2];
var year = parts[0];
var currentdate = new Date();
var cur_month = currentdate.getMonth() + 1;
var cur_day = currentdate.getDate();
var cur_year = currentdate.getFullYear();
if(cur_month==month && day >= cur_day)
{
alert("in this month");
}
else
{
alert("not in this month");
}
Can anyone help me plz?
in database the created date is like "2018-12-01 18:51:41".Based on this date i want to pare this date with current month.If current month is not equal to created date just show alert "not in this month".
I tried this code so far
const dateTime = "2018-09-01 18:51:41";
const parts = dateTime.split(/[- :]/);
var month = parts[1];
var day = parts[2];
var year = parts[0];
var currentdate = new Date();
var cur_month = currentdate.getMonth() + 1;
var cur_day = currentdate.getDate();
var cur_year = currentdate.getFullYear();
if(cur_month==month && day >= cur_day)
{
alert("in this month");
}
else
{
alert("not in this month");
}
Can anyone help me plz?
Share Improve this question edited Dec 6, 2018 at 4:15 becool asked Dec 6, 2018 at 3:29 becoolbecool 812 gold badges3 silver badges11 bronze badges 4-
1
day
should beparts[0]
andyear
should beparts[2]
? – Thum Choon Tat Commented Dec 6, 2018 at 3:33 - I tried the same script for todays date it seems working in chrome plnkr.co/edit/M9TLNOe4zeLxbvp3dJm2?p=preview – Siva Karthikeyan Commented Dec 6, 2018 at 3:34
- Your code working fine. – Shubham Baranwal Commented Dec 6, 2018 at 3:36
- i have updated my code plz check it – becool Commented Dec 6, 2018 at 3:38
2 Answers
Reset to default 4You only need to check with month and year value. Don't consider date in your condition. Have a look to my code -
const dateTime = "2018-11-01 18:51:41";
const parts = dateTime.split(/[- :]/);
var month = parts[1];
var year = parts[0];
var currentdate = new Date();
var cur_month = currentdate.getMonth() + 1;
var cur_year = currentdate.getFullYear();
if (cur_month == month && year == cur_year) {
alert("in this month");
} else {
alert("not in this month");
}
You only need to check that currentMonth === dateMonth && currentYear === dateYear. If they are then you are in the current month and don't need to check the day.
本文标签: jqueryHow to check given date is equal to current month using javascriptStack Overflow
版权声明:本文标题:jquery - How to check given date is equal to current month using javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742218923a2435079.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论