Truncated incorrect time value: '1:05 AM'

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • crs27
    New Member
    • Jul 2007
    • 40

    Truncated incorrect time value: '1:05 AM'

    Hai All,

    This is my create statement
    [code=mysql]
    CREATE TABLE `dbname`.`table name` (
    `vh_id` int(10) unsigned NOT NULL,
    `gh_utc` time NOT NULL,
    `gh_mydate` date default NULL,
    `gh_serverdate_ time` timestamp NOT NULL default CURRENT_TIMESTA MP,
    KEY `FK_geo_gpsdata _2` (`vh_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;[/code]

    when i query this table im getting "Truncated incorrect time value: '1:05 AM"
    the below is the query.Not getting why the time value is truncated.
    [code=mysql]
    SELECT time_format(gh_ utc ,'%H:%m:%s'),
    date_format(gh_ mydate,'%d/%m/%Y')
    FROM tablename where vh_id='1' and timestamp(gh_my date,gh_utc)
    between timestamp('2009/01/01','1:05 AM') and timestamp('2009/01/16','1:05 PM') ;[/code]

    Awaiting for the reply.

    Thanks in advance
    Last edited by Atli; Jan 12 '09, 05:20 AM. Reason: Added [code] tags.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    The string "1:05 PM" is an invalid time value. MySQL uses a 24 hour "HH:MM:SS" syntax.

    As a result, MySQL *truncates* the value you gave it and turns it into the most likely alternative that fits the required syntax, which becomes "01:05:00".

    To get the effect you are after, you need to use "13:05" for the PM value and "01:05" for the AM value.

    Comment

    • crs27
      New Member
      • Jul 2007
      • 40

      #3
      thanks for the reply Atli.
      I realized that,but i did not want to add 12 in my logic and then to make it 24 hr time.
      Is their any other way that i get 24hr time in the query itself.

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        You could use the STR_TO_DATE function to convert it into a valid value.

        Although, I would advise you to have your front-end do this conversion instead. It's a lot cleaner that way.

        Comment

        • crs27
          New Member
          • Jul 2007
          • 40

          #5
          thanks again atli.Shal follow the same.

          Comment

          Working...