Check Datum mit Heute

Jan-Frederik Stieler

Monsterator
Moderator
Hi,
da ich eh ne ganze Menge PHP-Variablen an JS übergeben muss habe ich mich entschieden dies auch mit dem Datum zu machen.


Javascript:
<?php
        date_default_timezone_set("Europe/Berlin");
        $todayJS = new DateTime('now');
        $todayJS = $todayJS->format('Y-m-d');
?>

        var todayJS        = '<?php echo $todayJS ?>';
        var discountendJS  = '<?php echo $discountJS->discountend(); ?>';

        var todayJS        = new Date(todayJS);
        var discountendJS  = new Date(discountendJS);

       console.log('todayJS: ' + todayJS + '; discountendJS: ' + discountendJS);

hier bekomm ich aber in der Console todayJS: Invalid Date; discountendJS: Invalid Date.
Somit funktioniert mein if-clause auch nicht richtig:
Javascript:
if(todayJS < discountendJS){
        console.log('discountprice ist angerechnet');
        if(typeof earlyconferencePriceJS !== "undefined"){
            $('#table-4 td').html(function () {
                return $(this).html().replace(earlyconferencePriceJS, '<span class="line-through">' + earlyconferencePriceJS + '</span> ');
            });
        }

        if(typeof conferencePriceJS !== "undefined"){
            $('#table-4 td').html(function () {
                return $(this).html().replace(conferencePriceJS, '<span class="line-through">' + conferencePriceJS + '</span> ' + discountPriceJS + ' (Discountprice)');
            });
        }
    }
    else {
        $('#discountAlertOne').removeClass('hidden');
    }

Ich hab hier irgendwie ein problem mit den Datum-Strings und -Objekten nur weiß ich grad nicht was ich jetzt genau machen soll?

Grüße
 
Hi,

über den Timestamp hast du es schon versucht?
Javascript:
new Date(<?php echo time(); ?> * 1000)

Ciao
Quaese
 
Hi,
hab grad rausgefunden das ich ja mein Variablen todayJS und discountendJS doppelt deklariert habe. Siehe doppeltes Schlüsselwort var.
Dank Dir.
 
Zurück