Welcome Guest, Not a member yet? Register   Sign In
CURDATE() and INTERVAL in codeigniter
#11

[eluser]Thiago Leao[/eluser]
[quote author="InsiteFX" date="1329310285"]You can try this, but then you will need to use set on all the fields.
Code:
$this->db->set('date_finish = DATE_ADD(CURDATE(), INTERVAL 30 DAY)');

// or
$array = array('id_products' => $id_products, 'date_start' => CURDATE(), 'date_finish' => 'DATE_ADD(CURDATE() + INTERVAL 30 DAYS)');
[/quote]

did not work!

DB

id_buy id_products id_user date_start date_finish
12 178 0 0000-00-00 0000-00-00
#12

[eluser]Mauricio de Abreu Antunes[/eluser]
Are you using MySQL?
You need to pass date with the right format.

Print your curdate and compare with your format database date field.

When you insert a strange string into date colummn, he just inserts 0000-00-00.

[EDIT]: why are you using CURTADE as php function? Put this function into your string.
#13

[eluser]Thiago Leao[/eluser]
using the same string is returned as zero!
#14

[eluser]Mauricio de Abreu Antunes[/eluser]
Code:
//create your array first
$array = array();
//use the set method
$this->db->set($array);
$this->db->insert('your_table_name');

according to manual, its not needed to pass your array in insert, just your table name.
#15

[eluser]Thiago Leao[/eluser]
???
#16

[eluser]Mauricio de Abreu Antunes[/eluser]
Don't argue with "???". Its a little bit offensive and not mature for a programmer.

Try out this:
Code:
function insertBuy($id_products) {
  $this->load->helper('date');
  $array = array('id_products' => $id_products,
                 'date_start' => 'CURDATE()',
                 'date_finish'=> 'CURDATE() + INTERVAL 30 DAYS');
  $this->db->set($array);
  $this->db->insert('buy');
}
#17

[eluser]InsiteFX[/eluser]
What type od date field our you using in your table?

I think he should be using NOW() not CURDATE() by the looks of the date he displayed above!

#18

[eluser]Mauricio de Abreu Antunes[/eluser]
CURDATE() in MySQL returns this format YYYY-MM-DD and NOW() is YYYY-MM-DD HH:MI:SS

You use CURTADE for insert data in DATE type
And NOW for insert data in DATETIME type

Code:
SELECT CURDATE(); //2012-02-15
SELECT NOW();     //2012-02-15 12:21:00
#19

[eluser]Mauricio de Abreu Antunes[/eluser]
User your add days like this:
Code:
SELECT DATE_ADD('2012-02-15', INTERVAL 1 DAY); //2012-02-16

#20

[eluser]Thiago Leao[/eluser]
when I insert manually in mysql, it works perfectly!!!!
It is giving some problem in converting to CI!

Code:
INSERT INTO buy (id_products, date_start, date_finish) VALUES ('1', CURDATE(), CURDATE() + INTERVAL 30 DAY)




Theme © iAndrew 2016 - Forum software by © MyBB