简体   繁体   English

在 U-SQL 中获取当前和上个月的第一个日期

[英]Getting the 1st date of the current and previous month in U-SQL

How to get in U-SQL:如何进入U-SQL:

  • the 1st date of the current month当月的第一个日期
  • the 1st date of the previous month?上个月的第 1 天?

If I was using SQL I would write the following query (any idea how to write it in U-SQL?):如果我使用 SQL,我将编写以下查询(知道如何在 U-SQL 中编写它吗?):

 WHERE MyDate BETWEEN DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-1, 0) AND DATEADD(MONTH, DATEDIFF(MONTH, 0, getdate()), 0)

You can use C# expressions for that:您可以为此使用 C# 表达式:

DECLARE @startDayThisMonth DateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
DECLARE @startDayPreviousMonth DateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month - 1, 1);

@data = 
    SELECT 
        x
     FROM 
        y
    WHERE
        MyDate BETWEEN @startDate AND @endDate;

Examples can be found at this site .可以在此站点上找到示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM