#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    1
    Rep Power
    0
    I'm having a lot of difficulty with formating a date field from a MySQL datebase in PHP. I've tried mysql's "select date_format". I've also tried to use php's date(time,"M d, Y"), but I either get a date from 2038 or 1969. The date format in the mysql datebase is timestamp(14). Any code on displaying this data type in php would be greatly appreciated.



    ------------------
    Bull
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    61
    Rep Power
    14
    make your mySQL table date an INT(11) column. It'll put the UNIX time stamp in. When you pull it out of the database, format it using the PHP date() function.

    something like this....

    $query = mysql_query("SELECT date FROM blah;");
    $fetch = mysql_fetch_row($query);

    $date = date('m/j/Y', $fetch[0]);

    find the letters to format the date function somewhere in the php.net documentation

    [This message has been edited by Atticus (edited October 22, 2000).]
  4. #3
  5. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    Stick with mysql's date and time datatypes over unix types, UNLESS you have to do a lot of juggling with the data or need to have it in several different formats.

    What problems are you having with the date_format function? How are you trying to use it?
  6. #4
  7. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,642
    Rep Power
    4492
    Are you sure the data is being put into mysql correctly? Can you show us the syntax of the sql statement involving date_format your using and how you're putting the date into the database? It's better to use the mysql functions that to change everything over to unix timestamps. It just adds a level you don't need to bother with...

    ---John Holmes...

    [This message has been edited by SepodatiCreations (edited October 22, 2000).]
  8. #5
  9. Wiking
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Sep 2000
    Location
    Sweden
    Posts
    3,608
    Rep Power
    26
    Stick to timestamp and display it in php with:

    "select DATE_FORMAT(column_name, "%Y-%m-%d %H:%i") as time"
    ...
    Then just
    echo "$time" and you'll see something like 2000-10-23 11:20.

    You might wanna check the letter-synthax on date_format to make fit your needs, but as stated above works for me.

    / NoXcuz

Similar Threads

  1. Sort by my date format
    By Mickster in forum PHP Development
    Replies: 5
    Last Post: February 19th, 2004, 01:33 PM
  2. Empty date & date format
    By anca in forum Visual Basic Programming
    Replies: 2
    Last Post: February 17th, 2004, 04:38 AM
  3. Convert date format
    By RockyRR in forum MySQL Help
    Replies: 14
    Last Post: January 21st, 2004, 07:27 AM
  4. Change date format yyyy-mm-dd to dd-mm-yyyy
    By et_me in forum PHP Development
    Replies: 3
    Last Post: January 7th, 2004, 11:35 PM
  5. date format difficulties
    By php123 in forum PHP Development
    Replies: 3
    Last Post: January 1st, 2004, 02:55 PM

IMN logo majestic logo threadwatch logo seochat tools logo