Results 1 to 5 of 5

Thread: datetime (mysql) to array (php)

  1. #1

    Thread Starter
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362

    datetime (mysql) to array (php)

    What I want to do is to take a datetime format information in my database and take the datetime from now and substract the datetime in ym database to know when the data was registered in my database.

    My idea is to find a way to have the year,day,hour... seperated in some variable and do a substraction.

    Question 1 :
    Is there a way to do it without spliting all the data in some variable ( or an array) ?

    Question 2: How I do to solve my problem? I cant figure out how.

    Thx

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    You could try something like:

    Code:
    $date1 = date('Y-m-d', strtotime('2002-03-04'));
    $date2 = date('Y-m-d', strtotime('2002-03-02'));
    
    $a = strtotime($date1);
    $b = strtotime($date2);
    
    $diff = getdate(strtotime($date1) - strtotime($date2));
    
    echo $diff['mday'];
    Look up getdate() in the manual for more info.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    Thx but I cant Insert data in my database when the data is : datetime format.

    mysql:
    name---------type
    date_items datetime


    code :
    $sql = 'INSERT INTO market (id_items, price_items, date_items ) VALUES('.$id_w.', '.trim($price).', '.date("d-m-Y H:i:s").' )';



    error:
    Something is wrong in your syntax near of ' 2560, 08-06-2003 13:39:36 )'

  4. #4

    Thread Starter
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    Do I have to create in my database a format for my date?

  5. #5

    Thread Starter
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    I use timestamp and it work thx

Posting Permissions

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



Click Here to Expand Forum to Full Width