Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

php date manupliations

Options
  • 01-07-2002 9:32pm
    #1
    Registered Users Posts: 476 ✭✭


    anyone know of a nice way to

    i have a string which is in the format : d-m-Y H:i
    typical example : 01-07-2002 19:49

    can i easily change this into simple F s format to look like July 07 instead ? ?


Comments

  • Registered Users Posts: 476 ✭✭Pablo


    i could try the explode feature except that they have different seperators .


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    Try this function.


  • Registered Users Posts: 476 ✭✭Pablo


    thanks mate

    work so far
    [php]
    <?
    $date_eg = '01-07-2002 19:49';
    echo "$date_eg Date in the format received <BR>\n";
    echo strtotime ("$date_eg"), " php version of date <BR>\n";

    $st_val = strtotime ("$date_eg");
    echo "$date_eg date changed back to version that is readable \n<BR>";

    $today = date("M j");
    echo "$today version that i'd like to see";

    ?>
    [/php]
    output
    01-07-2002 19:49 Date in the format received 
    1166903340 php version of date 
    01-07-2002 19:49 date changed back to version that is readable 
    Jul 2 version that i'd like to see
    
    any way that i can explode a string into the different pieces ? like i will always want the 4th and 5th digit and the 1st and 2nd digit and discard the rest ? ?


  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    any way that i can explode a string into the different pieces ? like i will always want the 4th and 5th digit and the 1st and 2nd digit and discard the rest ? ?

    You can't explode() without a string to split on, but you can use the string functions to get what you need. Alternatively, you can access characters in a string by array elements, for example:

    [php]<?php

    $string = 'string';
    $ting = $string[1] . $string[3] . $string[4] . $string[5];

    ?>[/php]adam


  • Registered Users Posts: 476 ✭✭Pablo


    cool thanks adam ... know how to do it now ...
    [php]$br_date = $date_eg[3] . $date_eg[4] . $date_eg[0] . $date_eg[1];
    echo "<BR><BR>$br_date";
    [/php]
    and add some if's and else if's to get the month all nice .

    adios,
    p. icon14.gificon14.gif


  • Advertisement
Advertisement