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 Illustrious Member

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

    sarahk iTamer Staff

    Messages:
    28,494
    Likes Received:
    4,457
    Best Answers:
    123
    Trophy Points:
    665
    #4
    have you checked out the documentation at php.net/date ?
     
    sarahk, Aug 19, 2013 IP
  5. rhoula

    rhoula Well-Known Member

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

    rhoula Well-Known Member

    Messages:
    875
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    145
    #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