0

I have a table name user . in user have filed colomn 'date' .

in this colomn field 'date' have data like this

 users table 

id | name | email | date |

1  | jhon | a@gmail.com |  2021-06-07 |

2  | phil | b@gmail.com | 2020-06-07 |

i want to showed data where 'date' is year is less than 1 year from now.

from this table just show :

2 | phil | b@gmail.com | 2020-06-07 |

because this date is less than 1 year . i am using laravel .

Adhik Mulat
  • 538
  • 2
  • 10
  • 39

2 Answers2

1

You can use this query to get users which their date field are less than one year from now:

User::query()->where('date', '<', Carbon::now()->subYear())->get();
0

You want to show users who have "date" that is less than a year from now. You can write a query very easily for that.

$users = User::whereBetween('date', [now(), now()->addYear()])->get();

This will filter down the results who have "date" values between now and a year from now. now is a helper function that returns a carbon date instance.

Nazmul Alam
  • 109
  • 7