0

I want to get all records from now between a year ago but it's not working exactly. Made in CodeIgniter

This is my query , antything wrong with it ? :

    $currentDate = date("Y-m-d H:m:s");
    $yeardate=date('Y-m-d H:m:s', strtotime('-1 year'));
    $this->db->select('TimeStamp');
    $this->db->where('Transaction', 'COMPLETED');
    $this->db->where('TimeStamp>=',$yeardate);
    $this->db->where('TimeStamp<=',$currentDate);
    $query = $this->db->get('R_Logs');
    $results = $query->result();

Thanks in advance

David
  • 840
  • 6
  • 17
  • 37

3 Answers3

1

I forgot to add a space between TimeStamp <= and TimeStamp >= . My bad.

David
  • 840
  • 6
  • 17
  • 37
0

I think it might be easier to try Epoch time and then query off of that - e.g. Get epoch for a specific date using Javascript

That will convert the date to number of days since January 1, 1970. then from that you can subtract 365 days ( or use the yearInteger %4 trick to find out if it is a leap year)

Community
  • 1
  • 1
Andrew Bowman
  • 798
  • 9
  • 21
0

Change these two lines any try once:

$currentDate    = date("Y-m-d H:i:s");
$yeardate       = strtotime(date('Y-m-d H:i:s') . ' -1 year');

Dump your query and debug:

echo $this->db->last_query();
Nil'z
  • 7,487
  • 1
  • 18
  • 28