Site icon SmartTutorials.net

Date condition in between function MySql Query

Mostly in games we have requirement like information of player, those who are played in the last week. Here is the simple mysql query to check players who are played last week.

We use simple mysql function to fetch result from the mysql table. MySql functions are

1.NOW()
2.DATE_SUB()
3.BETWEEN

where
NOW()- is mysql date function which returns present date and time. ex. 2012-11-17 12:04:26
DATE_SUB(NOW(), INTERVAL 7 DAY) – this date function subtracts 7 days from present date,
here present date is 2012-11-17 12:04:26
subtracted output is 2012-11-10 12:04:26

here is the sample table player table

Result :

MySQL Query is

SELECT name, city, score FROM player_information where played_on BETWEEN DATE_SUB(NOW(), INTERVAL 7 DAY) and NOW()

The above query get player information those who played last week..

Exit mobile version