SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem with addtime() function

    Hi
    All
    This is samiuddin. I am having table in mysql which contain two fields like pickupdate and pickuptime.

    I am using the query on this table to add time

    suppose the pickupdate column is having the value as 2012-08-06 and pickuptime is having the value as 23:00:00

    select addtime('pickupdate pickuptime','2:00:00') from xyz ;

    but it is not adding the time, it is giving the result as 2:00:00

    but when I am writing the function with direct values it is working properl.
    select addtime('2012-08-06 23:00:00' ,'2:00:00')
    it is giving the result as 201208-07 1:00:00


    please help me out to resolve the issue

    thanks
    MD.Samiuddin

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Instead of having a date column and a time column, why not use a datetime column?

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,250
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by samiuddin.adse View Post
    select addtime('pickupdate pickuptime','2:00:00') from xyz ;
    you cannot add a time of 2:00:00 to a string

    plus, do what guido suggests, use a single datetime column
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    addtime() function problem

    Quote Originally Posted by r937 View Post
    you cannot add a time of 2:00:00 to a string

    plus, do what guido suggests, use a single datetime column

    Thanks for your reply.

    Dear Sir

    I even tried add only time column.

    for example

    addtime('pickuptime','2:00:00') the value in the pickup time is 4:00:00,

    but then also it is not working. It is giving only 2:00:00

    please help me out

    Thanks

  5. #5
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    'pickuptime' is a string
    pickuptime is a column name
    Get rid of the single quotes.

    It won't do you any good adding two hours to just the time though. What if you have date 2012-01-01 and time 23:00:00. What will happen if you add two hours to the time column?

    Like I said before, why don't you change your table layout and use a datetime column instead of the two separate columns your're using now?

  6. #6
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I got the solution by concatenating the two columns

    Quote Originally Posted by guido2004 View Post
    'pickuptime' is a string
    pickuptime is a column name
    Get rid of the single quotes.

    It won't do you any good adding two hours to just the time though. What if you have date 2012-01-01 and time 23:00:00. What will happen if you add two hours to the time column?

    Like I said before, why don't you change your table layout and use a datetime column instead of the two separate columns your're using now?
    Thanks for your reply. I got the solution I used concat function on those two columns and I got the expected result.


Bookmarks

Posting Permissions

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