Mysql php pdo select part of date value string entry

I want to select a part of a record in a database. The record I want to select is the date.

The date of recording is the format 07/02/2015 . I want to have a selection option where I can put the year and month option as a parameter for the search. I want to know the select request for ff.

  • How can I choose a specific year from the record (annual report)

    I want to select the entire record in the database with the current year or with 2014.

  • How can I select a specific month from a record (monthly report)

    I want to select the entire record in the database with the current month and current year or with X month and X year

0
date php mysql sql-server pdo
Jul 03 '15 at 10:43
source share
2 answers

Use BETWEEN Keyword

 SELECT * FROM tableName WHERE dateCol BETWEEN '01-01-2014' AND '31-12-2014'; 

for reference http://www.w3schools.com/sql/sql_between.asp

Select * FROM table WHERE date between two selected dates

0
Jul 03 '15 at 10:54
source share

Try

 SELECT * FROM TABLENAME where YEAR(DATE_FORMAT(STR_TO_DATE(COLNAME, '%d/%m/%y'), '%Y-%m-%d')) = '2014' SELECT * FROM TABLENAME where MONTH(DATE_FORMAT(STR_TO_DATE(COLNAME, '%d/%m/%y'), '%Y-%m-%d')) = x 
0
Jul 03 '15 at 10:57
source share



All Articles