Results 1 to 6 of 6

Thread: Timestamp

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Location
    Osaka
    Posts
    200

    Timestamp

    I want to store current timestamp (date+time).
    I have ste field data type as timestamp in mysql.

    I use mktime() to store current timestamp but it stores 000000000000 not correct timestamp.

    What could be the problem

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Timestamp

    Use NOW() in your sql query to insert the current time.

    As an aside, you should try to do as much logic work in the SQL as you can, this reduces the communication between application and DBMS.

    For example:
    Code:
    insert into `guestbook` (
      `id`,
      `name`,
      `time`
    )
    values (
      last_insert_id(),
      'Fred',
      now()
    );

  3. #3
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: Timestamp

    Just to add if you are storing timestamps in MySQL then when you want to retrieve them you should use MySQL to format them instead of PHP for the same reason that penagate said

    http://dev.mysql.com/doc/refman/5.0/...functions.html

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Location
    Osaka
    Posts
    200

    Re: Timestamp

    okay

    But then how to compare two timestamps now ?

    because now function returns 14 digits timestamp
    and mktime returns 13 digits.

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Timestamp

    Well, you can't compare timestamps from two different sources.

    You can also just retrieve the current time from MySQL like this:
    Code:
    select now();

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Timestamp

    Have a look at the date time functions in SQL. You can use UNIX_TIMESTAMP(date) function to convert it back to a timestamp.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

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