Jump to content

Recommended Posts

For some reason, this isn't working as I'd expect. The current value I'm trying to change starts as:

 

2013-02-13 16:30:00

 

I then use this query:

 

SELECT DATE_ADD(`end`, INTERVAL 30 MINUTE) FROM `my_table` WHERE `ID` = 3

 

And the result becomes:

 

2013-02-13 17:30:00

 

Now if I didn't know any better, it looks like 60 minutes was added, not 30.

 

When I then try using INTERVAL 2 HOUR, the result comes out as:

 

2013-02-13 19:00:00

 

It also seems to me that the result is 1.5 hours later, not two.

 

What am I not getting about this?? :confused:

Edited by aikorei
Link to comment
https://forums.phpfreaks.com/topic/274702-add_time-using-interval/
Share on other sites

Hey, nice smile :)

 

Thanks. ;)

 

I do not see the date-time string in your DATE_ADD function.

 

I tried passing the name of the column ('end') in as the first argument for DATE_ADD since that's the information I'm trying to alter. I'm not sure if this is the right way to go about it or not, but it does seem to be changing the value that's contained there where I expect it to.

 

I'm pretty much brand new at most of this, so if there's a better way I'm all ears.

 

And thanks for the response. =)

It also seems to me that the result is 1.5 hours later, not two.

2.5 hours. Both of them are 30 minutes beyond what you expected.

 

Where are you seeing the original and result values? And a totally random question that will probably lead nowhere, what timezone are you and your server in?

[edit] And on that note, what happens if you select `end` without any DATE_ADDing?

Edited by requinix

Where are you seeing the original and result values? And a totally random question that will probably lead nowhere, what timezone are you and your server in?

[edit] And on that note, what happens if you select `end` without any DATE_ADDing?

 

I'm working in phpMyAdmin, directly with the DB, watching the values change by using queries in phpMyAdmin. I'm in Seattle (PST), though I'm not sure where the servers are, to be honest.

 

When I run this simple query:

 

SELECT end FROM `my_table` WHERE `ID` = 3

 

current result is:

 

2013-02-13 17:00:00

 

(I've been tinkering a bit, trying to figure out what's happening, so it's not the same as when I posted above)

I used that query three times and got the following results:

 

SELECT `end`, DATE_ADD(`end`, INTERVAL 30 MINUTE) FROM `oyuvfn_app_appointments` WHERE `ID` = 3


2013-02-13 17:00:00 2013-02-13 17:30:00




SELECT `end`, DATE_ADD(`end`, INTERVAL 20 MINUTE) FROM `oyuvfn_app_appointments` WHERE `ID` = 3


2013-02-13 17:00:00 2013-02-13 17:20:00




SELECT `end`, DATE_ADD(`end`, INTERVAL 2 HOUR) FROM `oyuvfn_app_appointments` WHERE `ID` = 3


2013-02-13 17:00:00 2013-02-13 19:00:00

 

It seems as though the new value is being calculated correctly, but it's not replacing the old value. All of those values populated 17:00:00 as the start value...?

 

Edit: Perhaps I was only assuming DATE_ADD actually updates the cell...do I need to actually use UPDATE here? Also, this still doesn't explain what was happening earlier on. That was just weird (though I'm will to admit there may have been some operator error in there somewhere).

Edited by aikorei
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.