1
votes

I need a record whose year is just before the current year. My table schema and data is like this

aca_id|aca_start_date | aca_end_date 
------|---------------|-------------- 
1     |2013-04-01     |2014-03-31
3     |2015-04-01     |2016-03-31 
7     |2014-04-01     |2015-03-31 

I want to fetch the record depending on the current year condition is - if current date year is 2014 then fetch the 1st record because its aca_start_date is 2013 which just before 2014. If current date year is 2015 then fetch the record 2nd record. I cannot sort the table on aca_start_date because table is sorted on aca_id in descending order for other purpose.

Need guidance how can I do this job in MySQL query or if this is possible to do by using php

1
little unsuer as to the question but perhaps .. WHERE YEAR(aca_start_date)=(YEAR(CURDATE())-1) .. - user557846

1 Answers

1
votes

Here is one way:

select t.*
from table t
where year(aca_start_date) = year(now()) - 1
limit 1;