我有一个格式为 [过去两年] [365 日] 的日期。使用 SQL 或 excel 函数,我需要确定与此相关的日期。这一年始终是 2000 年代的最后两年。没有 2007 年之前的日期。有没有办法轻松做到这一点?我正在使用它进行快速检查,并试图避免为此花费大量的编码时间。
2 回答
In SQL, the date-handling functions seem to vary widely by SQL vendor, and there don't seem to be any good standard ways of handling date offsets. However, if you were a bit more specific about the specific SQL server you're using, someone might be able to provide an answer that applies.
In Excel, you can build a date for the first day of the year (e.g. 2008-01-01) and then add the number of days numerically, subtracting 1 so that the first day is still 2008-01-01; the resulting value, when formatted as a date, should be the precise date value. For example, =DATE(2008,1,1)-1+320
returns a date of 11/15/08 (at least in LibreOffice Calc).
您可以在 Excel 中尝试此公式,您的数据位于 A1 中
=DATE(LEFT(A1,2)+100,1,RIGHT(A1,3))