CodeIgniter Forums
How to add 7 days to mysql date? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How to add 7 days to mysql date? (/showthread.php?tid=9466)



How to add 7 days to mysql date? - El Forum - 06-25-2008

[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?


How to add 7 days to mysql date? - El Forum - 06-25-2008

[eluser]Armchair Samurai[/eluser]
Everything you need is here:

http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html


How to add 7 days to mysql date? - El Forum - 06-25-2008

[eluser]xwero[/eluser]
In CI form will this be something like
Code:
$this->db->set('date = DATE_ADD(NOW(), INTERVAL 7 DAY)');



How to add 7 days to mysql date? - El Forum - 06-25-2008

[eluser]Sumon[/eluser]
SELECT DATE_ADD('1998-01-02', INTERVAL 31 DAY);
Output: '1998-02-02'


How to add 7 days to mysql date? - El Forum - 06-26-2008

[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.


How to add 7 days to mysql date? - El Forum - 06-26-2008

[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;
and here is the database table:
Code:
CREATE TABLE `events` (
  `EventId` int(11) NOT NULL auto_increment,
  `EventDate` date NOT NULL default '0000-00-00',
  `EventTitle` varchar(250) NOT NULL default '',
  `EventVanue` varchar(250) NOT NULL default '',
  `EventDetail` longtext NOT NULL,
  PRIMARY KEY  (`EventId`)
);
-- Dumping data for table `events`
INSERT INTO `events` (`EventId`, `EventDate`, `EventTitle`, `EventVanue`, `EventDetail`) VALUES
(1, '2006-03-14', 'This Class is Created By Aminul', '[email protected]', 'Conatct Info:\nMd. Aminul Islam\nHouse- 310/B\nSoudi Coloni\nDhaka Cantonment\nBangladesh\nMobile- 880189512733'),

I hope this might helpful for you.


How to add 7 days to mysql date? - El Forum - 06-26-2008

[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?


How to add 7 days to mysql date? - El Forum - 06-27-2008

[eluser]Gewa[/eluser]
Thank you VEEEEEEEEEEEEEEEEEEEEEEEERY much. My development now will go on


How to add 7 days to mysql date? - El Forum - 08-21-2008

[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)