Date() not getting it.

Discussion in 'PHP' started by sittsait, Nov 14, 2008.

  1. #1
    Ok here are some lines:
    
    <span id="countdown<?=$taa;?>"><? echo date("Y-m-d H:i:s", $item_details['end_time'])." GMT-03:00";?></span>
    
    Code (markup):
    Everything seems to be correct. It uses a small .js file to calculate the time remaining between "now" and data stored in "mySQL" table.

    So first get the date then get items date then add zone function. After this script counts time to 0 and then prints CLOSED. (Its an auction).

    It works when i view auctions item details page:
    Time Left 2 days 01h 47m 24s

    But on the main page, where its supposed to show the same thing for featured products, it shows:
    1970-01-01 02:00:00 GMT-03:00

    Paths are correct. So whats is wrong? I just cant figure it out.

    :eek:
     
    sittsait, Nov 14, 2008 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Try this:

    <? echo date("Y-m-d H:i:s", strtotime($item_details['end_time']))." GMT-03:00";?>
     
    jestep, Nov 14, 2008 IP
  3. Shoro

    Shoro Peon

    Messages:
    143
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    That's the date that it outputs if the input timestamp is considered invalid. As a debugging measure, have it echo the value you $item_details['end_time'] and post here what it is.
     
    Shoro, Nov 14, 2008 IP
  4. sittsait

    sittsait Guest

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Ok, thanks for the replys.

    <? echo $item_details['end_time'];?>
    Code (markup):
    RESULTS:
    Nov. 15, 2008 18:20:06 
    Code (markup):
    So to test other variables etc. i used a simple php script:

    
    <?php
    $today = time();
    $event = $item_details['end_time'];
    $countdown = floor(($event - $today)/86400);
    echo "$countdown";
    ?>
    Code (markup):
    RESULTS:
    1

    So the MySQL part seems to be working.
     
    sittsait, Nov 14, 2008 IP
  5. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #5
    Your problem is that $item_details['end_time'] is not a timestamp. You need to convert it using strtotime before it can be used in the date function.
     
    jestep, Nov 14, 2008 IP
  6. sittsait

    sittsait Guest

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Im starting to think that is a bug in this .js file...

    <? echo date("Y-m-d H:i:s", strtotime($item_details['end_time']))." GMT-03:00";?>
    Code (markup):
    RESULTS:
    1970-01-01 02:00:00 GMT-03:00  
    Code (markup):
    Maybe you know some ajax/java scripts where i could easily use $item_details['end_time'] as a target date? Just like in this simple PHP code above, only it should do live counting.
     
    sittsait, Nov 14, 2008 IP
  7. xenous

    xenous Peon

    Messages:
    102
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I think you have more than one counters on your home page or the page you try to have working as you are mentioning the countdown works on singular countdown page (detail page) the js might be for one countdown. I suggest to change the countdown script. Just finished an auction site and was having same problem with old coders job. Just changed the script and now is working like a charm. If you want i can paste the code and js here. Just let me know.
     
    xenous, Nov 14, 2008 IP
  8. sittsait

    sittsait Guest

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Would be awesome xenous.
    My js file is meant for multible countdowns, but yeah...
    If you give me your js theres prob. alot of coding needed to make it fit my system.
    Thank you in advantage.
     
    sittsait, Nov 15, 2008 IP
  9. xenous

    xenous Peon

    Messages:
    102
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Was a quick fix so i did not edit the js or actions but the working is as follows

    Code is below js is in attachment.
    <?php 
     if($status == 'auc'){ $date = ($rs_pre['auc_endate']);}
     if($status == 'pre'){ $date = ($rs_pre['auc_startdate']);}
    $date = date('F j, Y H:i:s', strtotime($date));
    if($prop_status == 'Closed'){
    echo "Auction is over";
    } else {
    <span id="property_<?=$rs_pre[auction_id]?>"></span>
    <script language="javascript" type="text/javascript">
    countdown('property_<?=$rs_pre[auction_id]?>', "<?=$date?>", 3, 'Halloween');
    </script> <?php } ?>
    PHP:
     
    xenous, Nov 16, 2008 IP
  10. xenous

    xenous Peon

    Messages:
    102
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    sorry the attachment did not go but now is on this post
     

    Attached Files:

    xenous, Nov 16, 2008 IP