1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Format the output of date field

Discussion in 'PHP' started by rhoula, Aug 19, 2013.

  1. #1
    how can I format this output "<td><? echo $rows['name']; ?></td>" from a mysql database to: MM-DD-YY

    Please help thank you
    rhoula, Aug 19, 2013 IP
  2. PoPSiCLe

    PoPSiCLe Well-Known Member

    Messages:
    1,214
    Likes Received:
    108
    Best Answers:
    51
    Trophy Points:
    160
    #2
    How you'd format the output depends on what's in the $rows['name'] variable.

    Can you give an example of what this says now?

    Besides, having a date in a database with a column name "name" is a bit... wonky.
    PoPSiCLe, Aug 19, 2013 IP
    rhoula and sarahk like this.
  3. samyak

    samyak Active Member

    Messages:
    270
    Likes Received:
    7
    Best Answers:
    4
    Trophy Points:
    88
    #3
    If the column 'name' in the database is a timestamp, then you do this:
    Code (Text):
    1. <td><? echo date("m-d-Y", $rows['name']); ?></td>
    However if its a datetime, then you can do this:
    Code (Text):
    1. <td><? echo date("m-d-Y", strtotime($rows['name'])); ?></td>
    samyak, Aug 19, 2013 IP
    rhoula likes this.
  4. sarahk

    sarahk iTamer Staff

    Messages:
    17,407
    Likes Received:
    1,740
    Best Answers:
    37
    Trophy Points:
    510
    #4
    have you checked out the documentation at php.net/date ?
    sarahk, Aug 19, 2013 IP
  5. rhoula

    rhoula Active Member

    Messages:
    856
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    95
    #5
    rhoula, Aug 21, 2013 IP
  6. rhoula

    rhoula Active Member

    Messages:
    856
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    95
    #6
    Yes, that is the first thing I did before I came here looking for help. I got lost trying to figure out out how to get it done.

    I agree with you, but to explain exactly why It's named "name" is a very long story :)

    Thank you for your help :)

    Thank you so much for your help. I will try to see if that will work.
    rhoula, Aug 21, 2013 IP
  7. marht

    marht Active Member

    Messages:
    142
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    58
    #7
    We can try to use PHP explode() to create an array with your month, date and year or we can use a timestamp to generate a date with the date() function.

    It depends on the output. Please tell us what the output is when you view your code in your browser.

    Kind regards,

    Maarten
    marht, Aug 21, 2013 IP