Welcome Guest, Not a member yet? Register   Sign In
subtract from date.
#1

[eluser]snortop[/eluser]
Thise problem really anoy me.

Im trying to subtract 6 month from current date.
But it keep telling me errors.

Code:
$this->db->where('timestamp <', DATE_SUB(now() , INTERVAL 6 month));

timestamp = timestamp

anyone have a working code or where i can figur out have to do these.
#2

[eluser]danmontgomery[/eluser]
Code:
$this->db->where('timestamp < DATE_SUB(NOW(), INTERVAL 6 MONTHS)', NULL, FALSE);
#3

[eluser]snortop[/eluser]
ROFL... so easy have could i have missed that
#4

[eluser]Dennis Rasmussen[/eluser]
DATE_SUB() is an SQL function, but you're running it in PHP.

Code:
$this->db->where('timestamp <', 'DATE_SUB(now() , INTERVAL 6 MONTH)');

If I'm wrong then please tell me what kind of error you get.
#5

[eluser]snortop[/eluser]
Well.. first i keep getting parsing error.

Seach the web for some other way to work around. so i did finde some code and tried whit variable like.

Code:
$date = new DateTime();
$date->sub(new DateInterval('P6M'));
$this->db->where('timestamp <', $date);

and

Code:
$date = new datetime();
date_sub($date, date_interval_create_from_date_string('6 month'));
$this->db->where('timestamp <', $date);

error
Code:
Severity: 4096

Message: Object of class DateTime could not be converted to string

Filename: database/DB_active_rec.php

Line Number: 453

So i wrote here... just the 1 line i had first.

Then i though i had it whit the other code... didnt get error first time
Had die(); in it.
Then i got these error.:

Code:
A Database Error Occurred

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'MONTHS)' at line 2

DELETE FROM `ci_visitor_activity` WHERE timestamp < DATE_SUB(NOW(), INTERVAL 6 MONTHS)
#6

[eluser]snortop[/eluser]
dont get a error anymore, but the other code not working.. that another problem.

Would hear have someone/anyone else would do it ;-)
#7

[eluser]snortop[/eluser]
Well my code keep deleting new post.. so something still wrong in it.




Theme © iAndrew 2016 - Forum software by © MyBB