Adding Days To Dates In MySQL
One of my customers recently asked me to increment the date field on an event in their database by 14 days because their upcoming event got delayed. I knew the SQL statement would be simple and after doing some quick research, I found the magical SQL:
UPDATE events SET date_starts = DATE_ADD(date_starts,INTERVAL 14 DAY) WHERE event_id = 3;
This works on DATE and DATETIME field types. Note that it's "14 DAY" and not "14 DAYS".
I work with an awesome cast of developers at Mozilla, and one of them in Daniel Buchner. Daniel's shared with me an awesome strategy for detecting when nodes have been injected into a parent node without using the deprecated DOM Events API.
CSS filter support recently landed within WebKit nightlies. CSS filters provide a method for modifying the rendering of a basic DOM element, image, or video. CSS filters allow for blurring, warping, and modifying the color intensity of elements. Let's have...
I recently received an email from a MooTools developer asking a great question about my LazyLoad class:
"I'm using your LazyLoad MooTools plugin (which is great, by the way). I have been trying to figure out how to modify it so that once an image scrolls into...
Some of the finest parts of web apps are hidden in the little things. These "small details" can often add up to big, big gains. One of those small gains can be found in keyboard shortcuts. Awesome web apps like Gmail and GitHub use loads of...
Nice but I use the time() function, what is better ?
@Catar: I don’t know which one is better, per say, but I know that this worked wonderfully!
it’s good!!!!…works fine and it’s usefull for me. tks!!
Nice! Wouldn’t have occurred to me that MySQL had such a feature. Personally I prefer to do all my data arithmetic in seconds before handing the result over to an SQL query, but this is worth noting.
Your blog is my Quick Bible in the Caos of Days
hi,
i’m new to sql and i’m using mysql workbench to generate data mart. i need help..i want to generate dates (e.g. 2005-01-01), day of week ( 1 to 7), day of month (1 to 31), day name and month name for the whole of year 2005. the primary key is the date_key which starts from 1 to 365 and i already upload the date key into my database. it just that i need to generate all the above attributes using update/set but i dont know what is the correct sql script to generate them automatically and accordingly. would appreciate if u could help me on this..thanks
Ok- That is helpfull but I want something like
” In a form an event is being added and it is add date is set to system date (today) Now I want the Event Expiry date to be automatically added in the event Expiry Date column based on the user choice. i.e User is give the choice to select that the event will expire in Two weeks, four weeks or Six weeks from the date of Adding”
Thanks! I’ve been banging my head on the wall with this and your solution worked perfectly!
THANKS ITS HELPFUL FOR ME…..
Brilliant! You save my day, David!
More exciting that it could be:
UPDATE events SET date_starts = DATE_ADD(date_starts,INTERVAL amountofdays DAY) WHERE event_id = 3;
amountofdays is the name of the column in the same table;
thus date_starts could be calculated depending on special amountofdays meaning for each row.
if (nice && useful)
Print “Nice & useful post for me!”
else
print “Bad Post”
After execution give me result :
Nice & useful post for me! ;)
What if you wanted to add, say, 3 business days to a Thursday?
how can I add days?so that i can set the return days of borrowed books, this is a library system im making. pls help. thank you so much
…this was a life saver!!!!!
thank you man!!
+10
how about adding month,is it MON or MONTH?
I want to add 30 Working Days to yesterdays date while Saturday and Sunday both are not working days.
THANK YOU! I’ve been googling this for about 40 minutes (had to change 1864 records, way too much to do it manually) and your solution is the only one that worked for me :). And it’s almost 10 years old!