formatting time string from: 2007-05-30 11:46:34

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • monomaniac21

    formatting time string from: 2007-05-30 11:46:34

    hi i have a time string of the form: 2007-05-30 11:46:34 i would like
    to format this to 30/5/2007, how can i do this? thanks

  • Erwin Moller

    #2
    Re: formatting time string from: 2007-05-30 11:46:34

    monomaniac21 wrote:
    hi i have a time string of the form: 2007-05-30 11:46:34 i would like
    to format this to 30/5/2007, how can i do this? thanks
    Hi,

    You can use date() and functions like that.

    Or do it the oldfashioned way: By hand with explode.
    Here follows an example.
    It can be written a lot shorter, but in this way you can see what happens.

    $org = "2007-05-30 11:46:34";
    $parts = explode(" ",$org);
    // parts[0] now contains 2007-05-30
    // parts[1] now contains 11:46:34

    $dateparts = explode("-",parts[0]);
    // dateparts[0] is now 2007
    // dateparts[1] is now 05
    // dateparts[2] is now 30

    // assemble them, loosing the leading 0 with (int)
    $result = (int)dateparts[0]."/".(int)datepart s[1]."/".(int)datepart s[2];

    Not tested, but this approach works.

    Regards,
    Erwin Moller

    Comment

    • Joe Scylla

      #3
      Re: formatting time string from: 2007-05-30 11:46:34

      monomaniac21 wrote:
      hi i have a time string of the form: 2007-05-30 11:46:34 i would like
      to format this to 30/5/2007, how can i do this? thanks
      >
      echo date("d/m/Y", strtotime("2007-05-30 11:46:34"));

      prints out:

      30/05/2007


      Regards
      Joe

      Comment

      • Geoff Berrow

        #4
        Re: formatting time string from: 2007-05-30 11:46:34

        Message-ID: <f46ltb$8no$02$ 1@news.t-online.comfrom Joe Scylla
        contained the following:
        >echo date("d/m/Y", strtotime("2007-05-30 11:46:34"));
        >
        >prints out:
        >
        >30/05/2007
        And for dates up to the 13th of the month, is ambiguous

        --
        Geoff Berrow (put thecat out to email)
        It's only Usenet, no one dies.
        My opinions, not the committee's, mine.
        Simple RFDs http://www.ckdog.co.uk/rfdmaker/

        Comment

        Working...