How to manipulate date?

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

    How to manipulate date?

    If I have a date that looks like: 2005-12-07 10:10:00

    How could I manipulate it in php to say "Dec, 07, 2005"?

    I can separate the string at the space, but don't know where to go from
    there....thanks for any suggestions.

  • hendry

    #2
    Re: How to manipulate date?

    Format a local time/date according to locale settings


    Comment

    • Alvaro G. Vicario

      #3
      Re: How to manipulate date?

      *** Greg Scharlemann escribió/wrote (7 Dec 2005 17:46:43 -0800):[color=blue]
      > If I have a date that looks like: 2005-12-07 10:10:00
      >
      > How could I manipulate it in php to say "Dec, 07, 2005"?[/color]

      I think it easier to just get the date in unix timestamp format rather than
      a string. Afterwards, you can use several PHP date functions to display it,
      such as date() or strftime().

      I suppose it comes from a MySQL query so try this:

      SELECT UNIX_TIMESTAMP( date_field) FROM table


      --
      -+ Álvaro G. Vicario - Burgos, Spain
      ++ http://bits.demogracia.com es mi sitio para programadores web
      +- http://www.demogracia.com es mi web de humor libre de cloro
      --

      Comment

      • Chuck Anderson

        #4
        Re: How to manipulate date?

        Greg Scharlemann wrote:
        [color=blue]
        >If I have a date that looks like: 2005-12-07 10:10:00
        >
        >How could I manipulate it in php to say "Dec, 07, 2005"?
        >
        >I can separate the string at the space, but don't know where to go from
        >there....thank s for any suggestions.
        >[/color]
        Here's a method I've used (found it using Google a year or so ago):

        $a = '2005-12-07';

        $y = $a[0].$a[1].$a[2].$a[3];
        $m = $a[5].$a[6];
        $d = $a[8].$a[9];
        $unixtimestamp = mktime(0, 0, 0, $m, $d, $y);

        $display_date = date('F j, Y',$unixtimesta mp)

        --
        *************** **************
        Chuck Anderson • Boulder, CO

        Integrity is obvious.
        The lack of it is common.
        *************** **************

        Comment

        • Sadara

          #5
          Re: How to manipulate date?

          Greg Scharlemann wrote:[color=blue]
          > If I have a date that looks like: 2005-12-07 10:10:00
          >
          > How could I manipulate it in php to say "Dec, 07, 2005"?
          >
          > I can separate the string at the space, but don't know where to go from
          > there....thanks for any suggestions.[/color]

          $unixTimestamp = strtotime ("2005-12-07 10:10:00") ;
          echo date("M, d, Y", $unixTimestamp) ;

          Comment

          • NC

            #6
            Re: How to manipulate date?

            Greg Scharlemann wrote:[color=blue]
            >
            > If I have a date that looks like: 2005-12-07 10:10:00
            >
            > How could I manipulate it in php to say "Dec, 07, 2005"?[/color]

            echo date('M d, Y', strtotime('2005-12-07 10:10:00'));

            Cheers,
            NC

            Comment

            Working...