• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to add 7 days to mysql date?

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

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

http://dev.mysql.com/doc/refman/5.0/en/d...tions.html

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

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

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

#6
[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', 'aminulsumon@yahoo.com', 'Conatct Info:\nMd. Aminul Islam\nHouse- 310/B\nSoudi Coloni\nDhaka Cantonment\nBangladesh\nMobile- 880189512733'),

I hope this might helpful for you.

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

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

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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.