如何在SQL Server中获取当前月份数?
1月的意思我想要1和12月我想要12。
答案 0 :(得分:32)
这个怎么样:
SELECT MONTH(GETDATE())
这将返回值1到12,具体取决于月份。
See the relevant MSDN documentation for details - 整个文档网站免费提供供所有人咨询 - 使用它!
答案 1 :(得分:4)
答案 2 :(得分:2)
选择datepart(month,getdate())
答案 3 :(得分:1)
这是获得
的方法PARAMETER_VALUE
输出
10
答案 4 :(得分:0)
您可以这样尝试:
DECLARE month INT;
DECLARE transactionmonth INT;
SELECT NOW() into date;
SELECT MONTH(date) into month;
答案 5 :(得分:0)
干净简单
SELECT MONTH(NOW());
答案 6 :(得分:0)
在MySQL中,可以通过以下方式实现:
SELECT MONTH(CURDATE())
要么
SELECT * FROM tableName WHERE MONTH(dateColumn) = MONTH(NOW());
还可以将当前月份与任何DATE进行比较:
public class SubScriber
{
public SubScriber()
{
int i = 5;
Action action1 = () =>
{
Console.WriteLine("Event Fired action1");//not getting called
i = 11; //commenting this line will execute the subscription code
};
Action action2 = () =>
{
Console.WriteLine("Event Fired action2");//will be called
};
Console.WriteLine("Target 1 = "+ action1.Target);
Console.WriteLine("Target 2 = " + action2.Target);
PrismEvents.EventTest.Subscribe(action1);
PrismEvents.EventTest.Subscribe(action2);
}
~SubScriber()
{
Console.WriteLine("SubScriber destructed");
}
}
static void Main(string[] args)
{
new SubScriber();
GC.Collect(); //commenting this line will execute the subscription code
GC.WaitForPendingFinalizers(); // or Thread.Sleep(2000);
Console.WriteLine("Publish");
PrismEvents.EventTest.Publish();
Console.WriteLine("Press a key to finish");
Console.ReadKey();
}
答案 7 :(得分:0)
在H2数据库中:
SELECT MONTH(CURRENT_DATE), YEAR(CURRENT_DATE) ;
输出:
MONTH(CURRENT_DATE)| YEAR(CURRENT_DATE)
2 2020