right now i am displaying same countdown timer by default in all product view pages using below code. but i need different countdown timers in every product pages according to value we set for the attribute.
using custom module , we set Date & time for the attribute : ecomdev_expiry_date
as May 11 2016 - 12 : 15: 15
if current date & time is May 10 2016 - 12 : 15: 15
, than in view page i want to display
Time left to Buy : 24: 00: 00 and it should keep on updating as 23 : 59: 59 , 23: 59, 58 so on as like :
phtml
<?php
$end_datetime='2016/06/10 12:15:15';
$date = date( "Y/m/d H:i:s",strtotime($end_datetime));
$endstr= date(strtotime($date));
$nowstr = Mage::getModel('core/date')->timestamp(time());
$now = date('Y/m/d H:i:s', $nowstr); ?>
<span id="countdown" class"countdown">
<script>showtiming('<?php echo $date?>','<?php echo $now ?>')</script>
</span>
script
<script>
function showtiming(dt,no)
{
var end = new Date(dt);
var now_date= new Date(no);
var _second = 1000;
var _minute = _second * 60;
var _hour = _minute * 60;
var _day = _hour * 24;
flag_time = true;
timer = '';
setInterval(function(){showRemaining();},1000);
function showRemaining()
{
var date = no;
var now = new Date(date);
var de= now.getTime();
if ( flag_time ) {
timer = de;
}
var d = new Date(timer);
currentYear = d.getFullYear();
month = d.getMonth()+1;
var currentDate = d.getDate();
currentDate = currentDate < 10 ? '0'+currentDate : currentDate;
var hours = d.getHours();
var minutes = d.getMinutes();
var seconds = d.getSeconds();
minutes = minutes < 10 ? '0'+minutes : minutes;
seconds = seconds < 10 ? '0'+seconds : seconds;
var strTime = hours + ':' + minutes+ ':' + seconds;
timer = timer + 1000;
var now_time = currentYear+'/' + month+'/' + currentDate + ' ' + strTime ;
var now = new Date(now_time);
var distance = end - now;
if (distance < 0) {
if (distance>-3)
{
location.reload(true);
return;
};
clearInterval(timer);
document.getElementById('countdown').innerHTML = 'Completed';
return;
}
var days = Math.floor(distance / _day);
var hours = Math.floor((distance % _day) / _hour);
var minutes = Math.floor((distance % _hour) / _minute);
var seconds = Math.floor((distance % _minute) / _second);
if (days <10)
{days = '0' + days;}
if (hours <10)
{hours = '0' + hours;}
if (minutes < 10)
{ minutes = '0' + minutes;}
if (seconds < 10)
{seconds = '0' + seconds; }
if(days==00)
{
dytext = '';
}
else if(days==1)
{
dytext = '<span class="countdown-text">'+ days +' Day </span>';
}
else
{
dytext = '<span class="countdown-text">'+ days +' Days </span>';
}
if(hours==00) {
hrtext='';
}
else {
hrtext = '<span class="countdown-text">'+ hours + '</span>'+ ":";
}
if(minutes==00)
{
mintext='';
}else {
mintext = '<span class="countdown-text">'+ minutes +'</span>'+ ":";
}
sectext = '<span class="countdown-text">'+ seconds +'</span>';
document.getElementById('countdown').innerHTML = dytext + hrtext + mintext + sectext;
flag_time = false;
}
}
</script>
<script> showtiming('<?php echo $date?>','<?php echo $now ?>') </script>
$end_datetime=$_product->geteComdevExpiryDate();
check this showing the correct values?$_product->geteComdevExpiryDate();
and tell me what the output of that<?php $end_datetime=$_product->geteComdevExpiryDate();