Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

insight's avatar

How to query 'dob' date with datatype timestamp without time zone for age between from and to ages?

Dear Friends, I have a search form with 'age from' and 'age to' dropdown it's value range from 1-100 years. I need to search the query in a table with field 'dob' with datatype 'timestamp without time zone'. As a newbie I couldn't estimate how it can do ? any body can advise how it can do .

Waiting your fast reply Thanks Anes P A

0 likes
2 replies
bobbybouwmann's avatar

Normally you would store the date of birth as a date in the database. After that, you can simply do a between date query

Model::whereBetween('date_of_birth', ['2000-01-01', '1990-01-01'])->get();

You need to determine the range for the dates in this query, but that is up to you ;)

insight's avatar
insight
OP
Best Answer
Level 2

Dear Bobby, I got the solution. Thanks for your answer . My solution query is select count(*) from public.tbl_first r join public.tbl_second m on r.id=m.first_cardid where DATE_PART('year',dob)> 1922 and DATE_PART('year',dob) < 2021

Thanks Anes

1 like

Please or to participate in this conversation.