Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder musher's Avatar
    Join Date
    Jan 2005
    Location
    Minnesota
    Posts
    203
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to store 3 seperat post values into a time field in a MySQL table

    I am setting up a form to except time I've set up 3 drop down boxes
    - Hour (1 - 12)
    - Min (15, 30, 45)
    - AM or PM

    what's the best way to get these three post values into a format to store in a MySQL time field
    Thanks
    Jim M

    "Lord, help me to become the person my dog thinks I am" - Dawn Ewing
    "If you must know. Yes, I do enjoy running after the dog sled when I fall off" - Me

    www.huskyzone.com -- Woodland Siberians

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Here are your options:

    http://dev.mysql.com/doc/refman/4.1/en/time.html

    I didn't see an option to specify AM/PM so I'm assuming you'll need to do something like add 12 to the hour if PM is selected.

  • #3
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Concatenate your values and use MySQL's STR_TO_DATE function as you insert:

    Code:
    INSERT INTO 
     table
    (timecol)
    VALUES
    (STR_TO_DATE('12:15 AM','%l:%i %p'))
    That time will be inserted as '00:15:00'.

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Oooh I forgot about STR_TO_DATE; I like that answer a lot better!

  • #5
    Regular Coder musher's Avatar
    Join Date
    Jan 2005
    Location
    Minnesota
    Posts
    203
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks guys, got it workin. Now all I need to make me happy is some cold weather and snow on the ground.
    Thanks
    Jim M

    "Lord, help me to become the person my dog thinks I am" - Dawn Ewing
    "If you must know. Yes, I do enjoy running after the dog sled when I fall off" - Me

    www.huskyzone.com -- Woodland Siberians


  •  

    Posting Permissions

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