Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Display Date from MySQL in PHP form

    All,
    Im guessing this is going to be easy for any one to answer bc im such a ****ing noob but here goes. I have mysql fields set to DATETIME and i just want to pull out that data and have it display in my form. And i would also like to know how to insert a date into a mysql DATETIME field if you guys would be so kind as to assist. I really really would appreciate any help. Thanks guys

  • #2
    Regular Coder
    Join Date
    Jul 2010
    Location
    Oregon City
    Posts
    280
    Thanks
    5
    Thanked 50 Times in 49 Posts
    for whatever type of form field you have, in the value field put <?php echo $dateTime; ?> where $dateTime is equal to whatever value u've pulled from the database.

  • #3
    Regular Coder
    Join Date
    Sep 2011
    Posts
    410
    Thanks
    18
    Thanked 26 Times in 26 Posts
    Now I'm not positive on this, but from my previous experience on using the datetime format in the mysql db, it updates every time the row is updated. I'm not sure exactly because I never looked it up and I'm sure someone is going to come around and correct me on it but from what happened to me, every time I updated the row, the time updated of when it was updated.

  • #4
    New Coder
    Join Date
    Jan 2012
    Posts
    10
    Thanks
    0
    Thanked 1 Time in 1 Post
    You can get it such as:

    PHP Code:
    $query "select mydate from `dates` where id='1'";
    $result mysql_query($query) or die(mysql_error());
    $row mysql_fetch_array($result);

    if(isset(
    $row['mydate']) {
        
    ## Use $row['mydate'] and print the date wherever you want it, as a string
        
    echo $row['mydate'];

    To insert one, you can use the following (this depends on your localization though):

    PHP Code:
    $query "insert into `dates` (mydate) values (" date("Y-m-d H:i:s") . ")";
    mysql_query($query) or die (mysql_error()); 
    For more information about date(), check this page:
    http://php.net/manual/en/function.date.php

  • Users who have thanked Kekke for this post:

    Red_Rain (01-12-2012)

  • #5
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Kekke,
    THANK YOU SO MUCH! Ive done tons of reading and you made the most sense to me. Thanks a million man.

    TO everyone else who tried to help, thank you for your time. You guys are awesome


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •