how to get only month and year value in sql from textbox with textmode property as month? asp.net c#

I am using Textbox with property Textmode month for year and month picker instead of date picker, how can I get the month value and year value from "2016-03" in sql?

I tried MONTH('2016-03') and YEAR('2016-03') but it does not work.

Answers


Try this MONTH('2016-03-01') and YEAR('2016-03-01')


select * from participants where 
        year(registerdate) = 2016 
and     month(registerDate) = 1

This works for me


The Question is tagged to C# also So This may also help you;

        string dateString="2016-03" // will be the input
        DateTime d;
        if (DateTime.TryParse(dateString, out d))
        {
            string monthName = d.ToString("MMMM", CultureInfo.InvariantCulture); // Will gives you the Month name
            int year = d.Year; // Will give you the year
        }

You can use a combination of STR_TO_DATE(), YEAR() and MONTH() to achieve that.

mysql> SELECT YEAR(STR_TO_DATE('2016-03', '%Y-%m')), MONTH(STR_TO_DATE('2016-03', '%Y-%m'));
+---------------------------------------+----------------------------------------+
| YEAR(STR_TO_DATE('2016-03', '%Y-%m')) | MONTH(STR_TO_DATE('2016-03', '%Y-%m')) |
+---------------------------------------+----------------------------------------+
|                                  2016 |                                      3 |
+---------------------------------------+----------------------------------------+
1 row in set (0.00 sec)

Need Your Help

Method has incorrect signature

android-studio

Despite having the method onButtonHomeClick declared in the Java file MainActivity, when I attempt to reference the method in the XML I receive the error message: "Method onButtonHomeClick in

SQL Oracle openquery to get items and location of items

sql sql-server oracle openquery

I am using an openquery to an Oracle server to get information from BaaN ERP.