[solved]dbal.sql query filter data with dates how?

Discussion forum for MOD Writers regarding MOD Development.
Locked
User avatar
irdem
Registered User
Posts: 172
Joined: Sat Oct 13, 2007 10:31 pm
Contact:

[solved]dbal.sql query filter data with dates how?

Post by irdem »

Hello,
I am trying to make a sql query that it could filter the data from database:
- I have 5 variables can be definable on ACP: dates_id, first_date, last_date, date_title, date_description
- the date format that i use : $today = date( 'Y-m-d' );
- finaly, I would like to filter the data from database like "if $today >= first_date and $today < last_date ".

my sql statement is:

Code: Select all

	$sql = 'SELECT dates_id, date_img, first_date, last_date, date_title, date_description, bbcode_uid, bbcode_bitfield
		FROM ' . IMPORTANT_DATES_TABLE . '
		WHERE date_title = ' . (int) $date_title . '
		ORDER BY dates_id ASC';
I would like to make it like, but it doesn't work:

Code: Select all

	$sql = 'SELECT dates_id, date_img, first_date, last_date, date_title, date_description, bbcode_uid, bbcode_bitfield
		FROM ' . IMPORTANT_DATES_TABLE . '
		WHERE date_title = ' . (int) $date_title . '
			AND ' . $today . ' >= first_date
			AND ' . $today . ' < last_date
		ORDER BY dates_id ASC';
how can I solve the problem for have a result like this function makes:
if ($today >= $row['first_date'] && $today < $row['last_date'])
{
................
}

thank you in advance.
Last edited by irdem on Tue Sep 25, 2012 11:08 am, edited 1 time in total.

User avatar
AmigoJack
Registered User
Posts: 5697
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: dbal.sql query filter data with dates how?

Post by AmigoJack »

irdem wrote:it doesn't work
I don't know any single software which is using that as error description.

You have to use string literals properly.
Wrong:

Code: Select all

WHERE 2012-09-25 >= first_date
Right:

Code: Select all

WHERE '2012-09-25' >= first_date
The worst thing about censorship is ███████████
Affin wrote:
Tue Nov 20, 2018 9:51 am
The problem is probably not my English but you do not want to understand correctly.
...
We will not come anybody anyway, nevertheless, it's best to shit this.

User avatar
irdem
Registered User
Posts: 172
Joined: Sat Oct 13, 2007 10:31 pm
Contact:

Re: dbal.sql query filter data with dates how?

Post by irdem »

thank you AmigoJack,
this little detail has solved my problem.

Locked

Return to “[3.0.x] MOD Writers Discussion”