This topic is locked

Limit the number of result on list page by date

3/13/2025 1:24:58 PM
PHPRunner General questions
A
anthonywalker author

Hello,

Im building a small database which will be ran from an iPad with slow internet, I want to only show entries on the list from "todays date" when logged in as a certain user.

Any help would be greatly appreciated!

Regards
Anthony

HJB 3/13/2025

https://asprunner.com/forums/topic/28556-I-want-to-show-last-week-this-week-next-week-date-as-filter-just-like-other-wizards

... for inspiration purposes only ...

P.S. Seen code mentions "7" for a week, so for only one day, you would need to adjust to "!"

A
anthonywalker author 3/13/2025

Thanks for the reply cooper21!

Ive tested your recomendation but I cant seem to get the results?

img alt

For example im using date=13/03/2025 in the WHERE clause but it says No results found in the list..
For example im using date=now() in the WHERE clause but it says No results found in the list..
For example im using date=CURRENT_DATE in the WHERE clause but it says No results found in the list..

As you can see all the entires ive done are today and are showing in the list:

img alt

Any idea what im doing wrong?

Thanks
Anthony

C
Chris Whitehead 3/14/2025

This is just how I'd try find out why.

I'm wondering how you are storing the date, as using 13/03/2025 as a condition won't work, dates are stored in the tables usually as 2025-03-13, that's if your datatype is set to DATE and not DATETIME. if it's set to varchar then trying to perform any date related functions will fail such as reformatting or adding/subtracting days.

Using NOW() returns a timestamp rather than todays date so gives you 2025-03-14 05:05:37 which won't match the date due to the time, so you may have to use greater than or equal to in the condition.">=". your_date_field >= DATE_FORMAT(NOW(), '%Y-%m-%d')

You could also use your_date_field > DATE_SUB(NOW(), INTERVAL 1 DAY) which would set the date as yesterday and give you the records with todays date.

If you could put up a screenshot of your table fields with the settings that might help. maybe even a shot of the table with the data.

A
anthonywalker author 3/14/2025

Hi Chris,

Thanks for replying.

Ive tried both of your suggestions to no avail. Below are some of the screenshots you requested:

img alt

img alt

img alt

Thanks
Anthony

A
anthonywalker author 3/14/2025

Ive also checked the database and the date is showing as: 2025-03-13T00:00:00.0000000

A
anthonywalker author 3/14/2025

Im getting the following error when using the now()

img alt

A
anthonywalker author 3/14/2025

Hi All,

I have figured it out, the query I needed was: CAST(date AS DATE) = CAST(GETDATE() AS DATE)

Thanks all!

C
Chris Whitehead 3/14/2025

Glad you've got it sorted.