Web Analytics Made Easy -
StatCounter insert timestamp? - CodingForum

Announcement

Collapse
No announcement yet.

insert timestamp?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • insert timestamp?

    Hi there do u know how i can insert the latest date & time in a timestamp field?
    How i can remove all the rows from the same table that are older than 3 minutes?
    Thx

  • #2
    Hi there do u know how i can insert the latest date & time in a timestamp field?
    How i can remove all the rows from the same table that are older than 3 minutes?
    Thx
    I think I know how you could realise your ojective, but timestamps are not the way to go. You better use a datetime-field.
    Storing the current datetime is then done like

    insert into table (yourdatetimefield) values(Now()) --> for new records
    update table set yourdatetimefield=Now() --> for existing records

    Removing the records older then 3 minutes is then
    delete from table where (yourdatetimefield < (DATE_ADD(Now(), INTERVAL -3 MINUTE)));


    Timestamps are meant as a 'stamp' that is automatically set when the record is created or updated. When you are setting the value yourself or when you have two timestamps in your table (cfr another thread here), then you are probably on the wrong track. So you either use a datetime-field if you want to specify the value yourself, or a timestampfield if you want the value to be generated automatically.
    Last edited by raf; Feb 24, 2004, 08:22 AM.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

    Comment


    • #3
      use NOW() in the query to get the timestamp value, ie

      INSERT INTO table ('timestampfield') VALUES ('NOW()')

      <edit>heh, hi raf, didn't see you up there</edit>

      Comment


      • #4
        i often get distracted when i have a post in progress, so it would be not uncommon that my session times out before i finish a post.

        I see your probably guiding him on the wrong path. He'll be thankfull now()

        (I'll better keep my mouth shut cause I see i messed up with the intended quoting in my post. Better edit it ...)
        Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

        Comment


        • #5
          xm...

          please take a look at my query
          INSERT INTO Session VALUES("0","192.168.64.11"," now() ")


          This inserts the value 00000000 to the timestamp field......
          What is wrong with it?

          Comment


          • #6
            You are trying to insert the string " now() " into your TIMESTAMP field, that's not gonna work, because a string won't give you any meaningful number of seconds. The correct query would be:

            Code:
            INSERT INTO Session VALUES("0","192.168.64.11", now())
            Although I do presume that the rest of the query should work properly. A tip: You can do an insert via phpMyAdmin's insert-tab, and see on the result page the SQL query used.
            De gustibus non est disputandum.

            Comment


            • #7
              " now() " --> if surrounded with doublequotes, the value is takes as a literal

              Now() --> is a function that returns the current dattimevalue

              So it should be
              INSERT INTO Session VALUES("0","192.168.64.11",Now())


              Also, change the double-quotes into single ones + specify the columnnames --> much safer + your query will keep working, if you add a column to the table.
              With your current query, it will throw an error.

              So your query should be

              INSERT INTO Session (namecolumn1, namecolumn2, namecolumn3) VALUES('0', '192.168.64.11',Now())

              <edit>crossposted</edit>
              Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

              Comment


              • #8
                thx

                it works fine...now/

                Comment

                Working...
                X