Adding Time data to MySQL

Discussion in 'MySQL' started by webber98, Nov 8, 2011.

  1. #1
    Hi. I'd like to add time (and no date, and not a timestamp) data to a field in MySQL through a PHP form. I've been having problems, as the date is also included. But I only want the time (I want to be able to sort the data by the time, and I think it was adding today's date along with the time, so if I enter the data on 5 different days, it won't sort correctly).

    PHP Insert Code:
    .strtotime($event_start_date).

    MySQL field:
    Type: INT
    Length/Values: 10
    Default: None
    Collation:
    Attributes: Unsigned
    Everything else empty

    Can anyone help with:
    1) what should the php insert code be like.
    2) what the field type, attributes, length/values, etc should

    Thanks!
     
    webber98, Nov 8, 2011 IP
  2. 2WDH.com

    2WDH.com Active Member

    Messages:
    143
    Likes Received:
    3
    Best Answers:
    5
    Trophy Points:
    68
    #2
    Hi Webber98.

    You can use "TIME" type for the time field and query like "INSERT INTO some_table SET time_field=CURTIME()".
     
    2WDH.com, Nov 12, 2011 IP
  3. Spudster

    Spudster Peon

    Messages:
    96
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Try SELECT * FROM "table name" it should select the time
     
    Spudster, Nov 12, 2011 IP
  4. som3on3

    som3on3 Active Member

    Messages:
    138
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    63
    #4
    use: strototime(date('d-m-Y'));
    that is the correct format. Your $event_start_date should be in the same format "d-m-Y"
     
    som3on3, Nov 13, 2011 IP