Findby DateTime the recent uploaded articles Symfony

Tags: , , , ,

Hello im triying to get on my dashboard only the most recent articles but isnt working i did this function

public function PostsRecientes(){
    return $this->getEntityManager()
    SELECT post
    FROM App:Posts post 
    WHERE post.fechaPublicacion > CURRENT_DATE()')

and this in my dashboardcontroller

 * @Route("/", name="dashboard")
public function index(PaginatorInterface $paginator, Request $request): Response
    $em = $this->getDoctrine()->getManager();
    $posts = $em->getRepository(Posts::class)->PostsRecientes();
    return $this->render('dashboard/index.html.twig', [
        'posts' => $posts

but when i do a var dump i doesnt bring any post.


You can use setFirstResult and setMaxResults, for example:

public function PostsRecientes()
    $qb = $this->createQueryBuilder('p')
        ->orderBy('', 'DESC')

    return $qb->getQuery()->getResult();

Source: stackoverflow