SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jan 2005
    Location
    doberman
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adding minutes to a stored time value

    hi all,

    I am trying to add minutes to a table in mysql. The person who created the table set time as varchar so I have to convert the time into a time format, then add the minutes, convert the result back to a string and finally update the table. I would like to do something llike this in sql but I don't know if its possible.

    Code:
    SELECT convert( alarm_time, time )  AS storedTime
    FROM timetable
    ADDTIME( storedTime, 00 :05 :00 ) AS newTime
    UPDATE timetable SET alarm_time = newTime WHERE task_id =729
    if not in sql anyone have any ideas on the cleanest way to do this in PHP?

    Thanks,

    Sum
    Got logical business solutions? Get SuM!
    Greg Starr (SuM)
    LogicStation.net
    Florida Based Contract Web Developer

  2. #2
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Look at using the Date and Time functions especially DATE_ADD
    Last edited by swdev; Feb 3, 2005 at 17:46. Reason: removed suggesiton for posting in the MySQL forums as it is posted there as well

  3. #3
    SitePoint Member
    Join Date
    Jan 2005
    Location
    doberman
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I saw that so I took your advise and am trying to use the DATE_ADD. I just posted here for some help.

    I have used it like this
    Code:
    UPDATE tasks SET alarm_time = DATE_ADD( 'alarm_time',  INTERVAL '00:05:00' HOUR_SECOND  )  WHERE task_id =729
    But since I can't get see what value this is giving me I can't understand why it's just setting my field blank. Sorry for the dual posts.
    Got logical business solutions? Get SuM!
    Greg Starr (SuM)
    LogicStation.net
    Florida Based Contract Web Developer

  4. #4
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you don't need the single quotes arount the alarm_time column

    try
    Code:
     UPDATE
       tasks
     SET
       alarm_time = DATE_ADD( alarm_time,  INTERVAL '00:05:00' HOUR_SECOND  ) 
     WHERE
       task_id = 729
    You could try running the SQL through phpMyAdmin or the MySQL command line and see what results you get
    Code:
     SELECT
       DATE_ADD( alarm_time,  INTERVAL '00:05:00' HOUR_SECOND  ) 
     FROM
       tasks
     WHERE
       task_id = 729


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
  •