dana
dana

Reputation: 5208

Jquery countdown timer adjustment

i am using a keith-wood jquery countdown timer plugin on my website (http://keith-wood.name/countdown.html), but i am initialisating it with data from my database. As in the specifications, in this plugin the first month is 0 (zero), so when i declare the data, i must decrease it with one (1). I don't know how to do it in my code:

my code:

<script>
    $(function () {
        var austDay = new Date();
        austDay = new Date( <? php echo date('Y', strtotime($sale - > end)) ?> , <? php echo date('m', strtotime($sale - > end)) ?> , <? php echo date('d-1', strtotime($sale - > end)) ?> , <? php echo date('h', strtotime($sale - > end)) ?> , <? php echo date('i', strtotime($sale - > end)) ?> , <? php echo date('s', strtotime($sale - > end)) ?> );
        $('#defaultCountdown').countdown({
            until: austDay,
            format: 'dHMS'
        });
    });
</script>

$sale->end is a datetime variable, and there at end))?> i need to decrease with one the month number. any idea about how can i do it?

thank you!

Upvotes: 1

Views: 1661

Answers (2)

Jacco
Jacco

Reputation: 23759

Your problem is that PHP's data() function ouputs a text-string instead of a number. So first you have to output the month and then subtract 1

<script type="text/javascript">
    $(function () {
        var austDay = new Date( <? php $timstamp = strtotime($sale - > end); echo date('Y,m,', $timstamp); echo(date('j', $timstamp) - 1); echo date(',h,i,s', $timstamp); ?> );

        $('#defaultCountdown').countdown({
            until: austDay,
            format: 'dHMS'
        });
    });
</script>

Upvotes: 2

Ivan
Ivan

Reputation: 3645

Well you can just subtract 1 from month:

<?php echo (date('m', strtotime($sale->end))-1)?>

Upvotes: 2

Related Questions