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
    Regular Coder
    Join Date
    Oct 2009
    Posts
    432
    Thanks
    6
    Thanked 3 Times in 3 Posts

    unable to to return part of date string using 'mdHi'

    I am trying to return only the numbers of a date string like so...
    Code:
    $futureDate = date("mdHi", strtotime(date("Y-m-d H:i:s") + '+ 10 minute'));
    But it is not returning the right date and time, it seems to be adding days as well and randomly.

    I have set the server datetime to London Uk in my script and this does not correct things.

    What is the correct way to get only the numbers of the date string that I am after.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,105
    Thanks
    23
    Thanked 594 Times in 593 Posts
    PHP Code:
    <?php
    $date 
    date('Y-m-d H:i:s');
    echo 
    $date.'<br>';

    $currentDate strtotime($date);
    $futureDate $currentDate+(60*10);             // ten minutes added here
    $formatDate date("m-d-H-i"$futureDate);   // Because mdHi is confusing for me.

    echo $formatDate.'<br>';
    ?>
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • Users who have thanked sunfighter for this post:

    needsomehelp (03-21-2014)

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You're confusing the time formats here. What's wrong with just using: date('mdHi', strtotime('+10 minute'));?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,105
    Thanks
    23
    Thanked 594 Times in 593 Posts
    Thanks Fou-Lu, I didn't know '+10 minute' would work although I'll never remember it when I need it. Don't use time/date function very much so have to look it up every time. Pun not intended.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #5
    Regular Coder
    Join Date
    Oct 2009
    Posts
    432
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Thank you Sunfighter, you highlighted that fact that I had one of the ending closing brackets in the wrong place. After I condensed your code you gave to one line.

    Code:
    $futureDate = date("mdHi", strtotime(date("Y-m-d H:i:s"))+(60*10));
    I left in the 'Y' in case the chances of someone trying to access this just before the new year!

    Thank you


  •  

    Posting Permissions

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