1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

mySQL timestamps

Discussion in 'MySQL' started by Weirfire, Oct 22, 2004.

  1. #1
    When you have a variable in a mySQL database which is of the timestamp format do you have to assign a value to the timestamp or does it do it automatically?
     
    Weirfire, Oct 22, 2004 IP
  2. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #2
    It's a number... so just use an integer.
     
    digitalpoint, Oct 22, 2004 IP
  3. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #3
    So would you recommend storing the date as a timestamp? :confused:
     
    Weirfire, Oct 22, 2004 IP
  4. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #4
    Depends on if you need the time or not. If you just need the date (and not time), then it's not necessary. If you want both date and time, it's a good format.
     
    digitalpoint, Oct 22, 2004 IP
  5. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #5
    Yes I need the time. :)

    Thanks Shawn.
     
    Weirfire, Oct 22, 2004 IP
  6. mushroom

    mushroom Peon

    Messages:
    369
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #6
    The first timestamp that is in a table is set to now(); on every insert or update automaticly even if you do not mention it.
    Reads or updates that make no changes to the row leave the timestamp unchanged.
     
    mushroom, Oct 22, 2004 IP
  7. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #7
    Thanks for your help Mushroom.

    I've got it going now :D
     
    Weirfire, Oct 23, 2004 IP
  8. Ozz

    Ozz Peon

    Messages:
    112
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Use datetime instead... timestamp is terrible. As Mushroom said timestamp is updated automatically unless you declare the value in the query... if you forget its going to be a disaster... specially if you want to create logs or statistics... lets say that you missed this detail in the query and an entire set of rows goes withthe wrong data (it happened to me once... lucky me I backed up the database before :D).

    In fact as I remember MySQL is going to change the way timestamps behave soon (in v4.1 or 5)... so again... its better to use datetime for me.
     
    Ozz, Oct 25, 2004 IP
  9. aspcoder

    aspcoder Peon

    Messages:
    132
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    If you use MySQL timestamp, you must use MySQL function date_format() in the MySQL select command.like a ,

    select date_format(now(),'%d-%m-%Y');

    and you can replace the now() function with any column with timestamp type.
     
    aspcoder, Dec 3, 2004 IP