How to properly use Between in Mysql

I want to fetch the data that i have stored in my database
my database has a table called tbl_event with a column names date_start and date end and I want to filter them

i want to fetch the events happening for this week what would be the proper syntax to do it? Thanks in advance! :slight_smile:

Something like

SELECT * FROM tbl_event 
WHERE date_start BETWEEN NOW() AND DATE_ADD(NOW(),INTERVAL 1 WEEK)

That will get all data for events starting from now and a week from now.

2 Likes

thank you sir! it worked Godbless!

[quote=“SamA74, post:2, topic:216483, full:true”]
Something like[/quote]

yes, something like that… but not that :wink:

if date_start is DATE, then you will actually exclude today if you use NOW()

hint: NOW() should be used only with DATETIMES

1 Like

yea i got it right thanks

sweet… so what was your column’s data type?

1 Like

its varchar actually and i was surprised that it worked

varchar? that’s bad

and yes, surprising

was any even returned from today? i’m guessing no

you should re-test it

it did work even though its data type is varchar it displayed the information that i want to see

did you test your query for events that are scheduled today?

because using NOW() you will fail to pick those up

1 Like

im using php and replaced NOW() as date(‘Y-m-d’);

I’m surprised it worked with varchar. Don’t you think it would be a good idea to change the column to DATE or DATETIME?

1 Like

dont worry i`ve already changed it :smile:

2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.