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 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2012
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Get day/month/year from date string?

    Please help! How can I get the date elements from a string?

    This is what I've got so far, but it's not working.

    PHP Code:
    $strDate "6/25/2012";
    $newDate date("j/n/Y",$strDate);

    echo 
    "day is " $newDate['mday'] . "<BR/>";
    echo 
    "month is " $newDate['mon'] . "<BR/>";
    echo 
    "year is " $newDate['year'] . "<BR/>"
    Thanks in advance,
    John.

  • #2
    New Coder
    Join Date
    May 2012
    Posts
    50
    Thanks
    6
    Thanked 4 Times in 4 Posts
    Try this-ish

    PHP Code:
    $strDate "6/25/2012"

    $t strtotime($strDate);
    $getDate getdate($t);

    printf('day is %d <br /> month is %d <br /> year is %d'$getDate['mday'], $getDate['mon'], $getDate['year'] ); 
    Edit: You can use $getDate[] as you wish. Doesn't have to be in printf function.
    Last edited by bjarneo; 10-22-2012 at 09:54 AM.


  •  

    Posting Permissions

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