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 8 of 8
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    74
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Convert 23/01/2012 to 20120123

    Is it possible to change the date format from 23/01/2012 to 20120123??
    Thanks
    Rob

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,546
    Thanks
    8
    Thanked 1,093 Times in 1,084 Posts
    $date="23/01/2012";
    $parts=explode("/",$date);
    $newdate=$parts[2].$parts[1].$parts[0];
    echo $newdate;

  • Users who have thanked mlseim for this post:

    robbiez (01-23-2012)

  • #3
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by mlseim View Post
    $date="23/01/2012";
    $parts=explode("/",$date);
    $newdate=$parts[2].$parts[1].$parts[0];
    echo $newdate;
    Exactly what I was just about to post
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • #4
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Wow, got a bad rep point for having a personality, and agreeing with someone.
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • #5
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,546
    Thanks
    8
    Thanked 1,093 Times in 1,084 Posts
    what is a rep point?

  • #6
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Reputation point. Under your name where you have all the green boxes - that's your reputation (kudos btw ). You can see the latest ones on your 'User CP'. You can give neutral, positive or negative points. You give them by clicking the wee medal, next to 'Report post'
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • #7
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,546
    Thanks
    8
    Thanked 1,093 Times in 1,084 Posts
    I guess I never knew what that meant ... what good is it ...
    Doesn't look like we can cash it in for anything.

    stupid idea.

  • #8
    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
    Rep is a builtin feature of the vB3+, and I believe thanks is an extension. They are pretty much the same thing really, except there is no 'chastise user for this post' option

    Also, another way to do this using 5.3+ uses the datetime:
    PHP Code:
    $sDate '23/01/2012';
    $dt DateTime::createFromFormat('d/m/Y'$sDate);
    print 
    $dt->format('Ymd'); 
    The pro with this is since its an actual datetime type, it is locale aware so you can add a timezone to correct the date if desired.


  •  

    Posting Permissions

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