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

    Join Date
    Jan 2000
    Location
    Malmö
    Posts
    13
    Rep Power
    0
    I want to store the current time in a mysql database with php. I would like the format to be:
    yyyymmddttmmss
    but any format will do for now.

    If it doesn't work in php, can I get the date/time with a perl script?
  2. #2
  3. 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
    You don't need to. Check out the DATETIME datatype for mysql. It stores and retrieves in two formats. A string "YYYY-MM-DD HH:MM:SS" or as an interger YYYYMMDDHHMMSS
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Location
    Malmö
    Posts
    13
    Rep Power
    0
    I want to compare the current date with the one stored in the mysql database to check time difference. How do I do that?
  6. #4
  7. 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
    You can use the mysql date/time functions, specifically date_add() and date_sub().

    Let's say you want the records where date is less than 7 days old.

    select * from table where date_add(date_field, interval 7 day)> now();

    See the mysql manual for more detail

Similar Threads

  1. Getting data from different tables in Mysql with PHP
    By Bosw8er in forum PHP Development
    Replies: 3
    Last Post: February 10th, 2004, 04:25 PM
  2. mysql date time stamp and UTF8
    By doomish in forum MySQL Help
    Replies: 0
    Last Post: February 8th, 2004, 08:37 AM
  3. search DB by date range
    By Simm in forum PHP Development
    Replies: 1
    Last Post: February 4th, 2004, 01:35 PM
  4. Replies: 13
    Last Post: February 2nd, 2004, 11:13 AM
  5. Store Date and time in SQL server datetime field
    By vikaspa in forum Visual Basic Programming
    Replies: 1
    Last Post: January 30th, 2004, 05:34 PM

IMN logo majestic logo threadwatch logo seochat tools logo