How to add 7 days to mysql date? |
[eluser]Gewa[/eluser]
Hi, I need such thing. I need to make in mysq query calculation of date that will come in 7 days or 30days. Lets says that today is 26-06-2008 . Is there any easy way to add 7 days and get the value of the day that will come in 7 days?
[eluser]Armchair Samurai[/eluser]
Everything you need is here: http://dev.mysql.com/doc/refman/5.0/en/d...tions.html
[eluser]xwero[/eluser]
In CI form will this be something like Code: $this->db->set('date = DATE_ADD(NOW(), INTERVAL 7 DAY)');
[eluser]Sumon[/eluser]
SELECT DATE_ADD('1998-01-02', INTERVAL 31 DAY); Output: '1998-02-02'
[eluser]AgentPhoenix[/eluser]
Interesting. I didn't know MySQL had those. Do other database types (Oracle, MS SQL, SQLite, PostgreSQL) have those as well? Personally, I've started doing everything with UNIX timestamps lately. It makes it pretty easy to store and display times, plus, when you want to add say 7 days, you can just do the math (number*86400) to find out the UNIX timestamp in the future.
[eluser]Sumon[/eluser]
Yes it's valid mysql query statement.I am using mysql version:5.0.45 Here it is once again with full explanation Code: UPDATE EVENTS SET EventDate = DATE_ADD( EventDate, INTERVAL 14 DAY ) WHERE EventId =1; Code: CREATE TABLE `events` ( I hope this might helpful for you.
[eluser]AgentPhoenix[/eluser]
Yeah, I realize it's valid MySQL, but I'm curious if the other databases CI supports do the same thing. I'd hate to build this functionality in through Active Record only to find that another database chokes on it. Anyone familiar with any of the other database types know off hand?
[eluser]Gewa[/eluser]
Thank you VEEEEEEEEEEEEEEEEEEEEEEEERY much. My development now will go on
[eluser]dare[/eluser]
UPDATE EVENTS SET EventDate = DATE_ADD( EventDate, INTERVAL 14 DAY ) WHERE EventId =1; ...................................................................................... Many Thanks .... this was very useful to me today ...... DATE_ADD( coloumn_name , INTERVAL 6 MONTH) |
Welcome Guest, Not a member yet? Register Sign In |