nvrmnd1
February 25, 2016, 4:36pm
1
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!
SamA74
February 25, 2016, 4:45pm
2
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
nvrmnd1
February 25, 2016, 4:49pm
3
thank you sir! it worked Godbless!
r937
February 25, 2016, 5:35pm
4
[quote=“SamA74, post:2, topic:216483, full:true”]
Something like[/quote]
yes, something like that… but not that
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
nvrmnd1
February 25, 2016, 6:00pm
5
yea i got it right thanks
r937
February 25, 2016, 6:25pm
6
sweet… so what was your column’s data type?
1 Like
nvrmnd1
February 26, 2016, 1:08am
7
its varchar actually and i was surprised that it worked
r937
February 26, 2016, 3:51am
8
varchar? that’s bad
and yes, surprising
was any even returned from today? i’m guessing no
you should re-test it
nvrmnd1
February 26, 2016, 3:08pm
9
it did work even though its data type is varchar it displayed the information that i want to see
r937
February 26, 2016, 4:03pm
10
did you test your query for events that are scheduled today?
because using NOW() you will fail to pick those up
1 Like
nvrmnd1
February 26, 2016, 4:21pm
11
im using php and replaced NOW() as date(‘Y-m-d’);
SamA74
February 26, 2016, 4:31pm
12
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
nvrmnd1
February 26, 2016, 4:33pm
13
dont worry i`ve already changed it
2 Likes
system
Closed
May 27, 2016, 11:33pm
14
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.