Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jun 2009
    Posts
    68
    Thanks
    22
    Thanked 0 Times in 0 Posts

    strtotime +1 day

    I have a date stored in my MySQL database: 2012-10-27 19:00:00

    When I use the following PHP code I get the date Saturday 27th October 2012 instead of Sunday 28th October 2012.

    Can anyone tell me what I'm doing wrong?

    PHP Code:
    <?php echo date("l jS F Y"strtotime($start_time,'+1 day')); ?>

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    You have the arguments backwards and the input for strtotime() is expecting a timestamp, so you need to pass it through strtotime() itself, or use the MySQL UNIX_TIMESTAMP() function when you request the field from the database so it gets returned as a unix timestamp instead of a MySQL date.
    PHP Code:
    $start_time '2012-10-27 19:00:00';

    echo 
    date('l jS F Y'strtotime('+1 day'strtotime($start_time))); // Sunday 28th October 2012 
    This also works:
    PHP Code:
    echo date('l jS F Y'strtotime($start_time ' +1 day')); 
    If you have PHP >= 5.3 you should consider using the DateTime class' add() function.
    Last edited by Inigoesdr; 10-26-2012 at 02:22 AM.

  • Users who have thanked Inigoesdr for this post:

    nickburrett (10-26-2012)

  • #3
    New Coder
    Join Date
    Jun 2009
    Posts
    68
    Thanks
    22
    Thanked 0 Times in 0 Posts
    Thank you...

    How would I apply that fix here?

    PHP Code:
        $row .= '<tr>

        <td>'
    .$start_time.'</td>
        <td>'
    .$client_first.' '.$client_last.'</td>
        <td>'
    .$dj_requested.'</td>
        <td>'
    .$quotation_status.'</td>
        <td><a href="update.php?id='
    .$id.'">Update</a></td>
        <td><a href="view.php?id='
    .$id.'">View</a></td>
        <td><a href="signature.php?id='
    .$id.'">Signature</a></td>
        <td><a href="delete.php?id='
    .$id.'">Delete</a></td>
        </tr>'


  • #4
    New Coder
    Join Date
    Jun 2009
    Posts
    68
    Thanks
    22
    Thanked 0 Times in 0 Posts

    Date does not display?

    Hello

    Could someone please tell me why my date is not displaying correctly. I'm assuming it's got something to do with $row but I don't know how to fix it?

    PHP Code:
    <?php include 'header.php'?>

    <table width="100%" border="1">

    <?php

    // Make a MySQL Connection
    include("connect.php");

    // Make a MySQL Connection
    $query "SELECT * FROM bookings ORDER BY start_time"
         
    $result mysql_query($query) or die(mysql_error());

    while(
    $row mysql_fetch_array($result)){
        
    ?>

    <tr>
    <td><?php echo date("l jS F Y"strtotime($start_time)); ?></td>
    <td><?php echo date("g:i a"strtotime($start_time)); ?> - <?php echo date("g:i a"strtotime($finish_time)); ?></td>
    <td><?php echo $row['client_first'?></td>
    <td><?php echo $row['client_last'?></td>
    <td><?php echo $row['dj_requested'?></td>
    <td><?php echo $row['quotation_status'?></td>
    <td><a href="update.php?id=<?php echo $row['id'?>">Update</a></td>
    <td><a href="view.php?id=<?php echo $row['id'?>">View</a></td>
    <td><a href="signature.php?id=<?php echo $row['id'?>">Signature</a></td>
    <td><a href="delete.php?id=<?php echo $row['id'?>">Delete</a></td>
    </tr>

    <?php
    mysql_close
    ();
    }
    ?>

    </table>

    <?php include 'footer.php'?>

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    What does it display as? I'd expect it'd be either January 1, 1970 or December 31, 1969 (check by adding F Y j to the date) at midnight. $start_time and $finish_time simply do not exist here, so you are saying that you want time 0, which is midnight between December and January on the 1969-1970 roll. Are these dates supposed to come from $row? The only thing we can tell here is that you for sure have a start_time in that table since you are ordering by it, but other than that we haven't a clue this structure.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •