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.

echo a date in a webpage

Discussion in 'PHP' started by pictureboarduk, Apr 20, 2010.

  1. #1
    Hi,

    I stored a date and time in a database using the mysql NOW() function.

    The field is of type datetime

    How can I use PHP to echo the stored value?

    I'm doing:

    
    $value = $row['order_DateTime'];
    echo $value;
    
    Code (markup):
    This doesn't work.

    I also tried:

    
    $value = $row['order_DateTime'];
    echo $value('l jS \of F Y h:i:s A');
    
    Code (markup):
    Which also doesn't work.

    Can anyone help me with this?

    I always say thanks for help.
     
    pictureboarduk, Apr 20, 2010 IP
  2. tguillea

    tguillea Active Member

    Messages:
    229
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    90
    #2
    Just to make sure we're on the same page, is the value being stored in the database properly? Try a print_r of the whole $row array - does the key "order_DateTime" have a value?
    You're probably going to have to echo it as follows to get it in the date / time format (because it should be stored as a Unix Timestamp, right?):

    
    $value = $row['order_DateTime'];
    echo date('n/j/Y h:i:s',$value);
    
    PHP:
     
    tguillea, Apr 20, 2010 IP
    pictureboarduk likes this.
  3. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #3
    If you stored the data correctly, the this will output something like;

    
    $result = mysql_query("SELECT post_date FROM wp_posts where id=2")
    $row = mysql_fetch_array( $result );
    print $row['post_date']."\n";
    
    Code (markup):
    OUTPUT: 2010-04-21 08:34:47

    You can chane the format of the output by using the date() function.

    http://uk2.php.net/manual/en/function.date.php

    If you arent getting any output, check the data in your database is correct first.
     
    lukeg32, Apr 21, 2010 IP
    pictureboarduk likes this.