Convert MYSQL timestamp into Readable PHP

Discussion in 'PHP' started by meganerd, Aug 9, 2006.

  1. #1
    I have a script that will insert a timestamp into the database with each new submission. However, when I call on the timestamp:

    I get it as MYSQL sees it:
    How can I convert this into:

    I don't care about the time part.

    Or is there a better way I could be doing this rather than using the timestamp?
     
    meganerd, Aug 9, 2006 IP
  2. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #2
    mad4, Aug 9, 2006 IP
  3. meganerd

    meganerd Peon

    Messages:
    105
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Darn it! I was trying to be lazy and you ruined it. :p Thanks.

    Just kidding.

    I'm a visual learner and when it comes to PHP, I learn backwards. I've tried for 5 years to read php.net and other help sites but it never sank in until I get the actual code. Only then could I learn how php works by dissecting the code and basically trial and error.

    However, I'm not using that as an excuse. I'm going to go to the url you suggested and see what I can come up with. Thanks!
     
    meganerd, Aug 9, 2006 IP
  4. meganerd

    meganerd Peon

    Messages:
    105
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yay! I found something to replace it.

    I changed date to varchar instead of timestamp. And then I used:

    on the form to auto come up with the date for me. And Wahoo! It's works. Thanks.
     
    meganerd, Aug 9, 2006 IP
  5. falcondriver

    falcondriver Well-Known Member

    Messages:
    963
    Likes Received:
    47
    Best Answers:
    0
    Trophy Points:
    145
    #5
    falcondriver, Aug 9, 2006 IP
  6. ip076

    ip076 Peon

    Messages:
    79
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I would say FalconDriver has the best idea. If you for some reason cannot do that, I would use a combination of php's date and strtotime functions.

    
    $NewDate = date("F jS, Y", strtotime($MysqlDate));
    
    PHP:
    Both of these I think are better options than storing the information from a hidden form variable. I could spoof your form and include anything in that field since you made it a varchar field.

    Use the built-in MySQL Date Functions...if not possible, use the PHP functions...
     
    ip076, Aug 9, 2006 IP
  7. webviz

    webviz Peon

    Messages:
    216
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    $date = date("F jS, Y", $timestamp_stored_in_db);
    PHP:
     
    webviz, Aug 9, 2006 IP
  8. ip076

    ip076 Peon

    Messages:
    79
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I'm not sure, will this work? The MySQL date given is more of a String Date than a Unix Timestamp, thats why I used strtotime.
     
    ip076, Aug 10, 2006 IP
  9. neebski

    neebski Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    <? echo $date = date("F js, Y", $row_logs['time']; ?>
    PHP:
    Eh? I cant seem to get it work on my end. Thoughts?
     
    neebski, Sep 21, 2007 IP
  10. falcondriver

    falcondriver Well-Known Member

    Messages:
    963
    Likes Received:
    47
    Best Answers:
    0
    Trophy Points:
    145
    #10
    try <? echo date("F js, Y", $row_logs['time']; ?>
     
    falcondriver, Sep 22, 2007 IP