Reputation: 23
I have a button that I want to only be displayed for 3 specific days at a certain time of day. Here is what I have so far:
$(document).ready(function()
{var pDate = new Date();
var pHour = pDate.getHours();
if
((pHour >= 10) && (pHour < 17))
{
$(".button5").show();
}
});
It works for displaying the button during a specified time frame(10-17), but how do I add limitations of Month and Day?
Upvotes: 2
Views: 950
Reputation: 689
You are looking for getMonth() and getDay() on the date object.
$(document).ready(function()
{
var pDate = new Date();
var pHour = pDate.getHours();
var pMonth = pDate.getMonth();
var pDay = pDate.getDay();
if
// show only the first month and first day between 10 and 17 hours of the day
((pHour >= 10) && (pHour < 17) && pMonth == 1 && pDay == 1)
{
$(".button5").show();
}
});
Upvotes: 1