如何创建将日期转换为文本的新列 [英] How to create a new column converting date to text
问题描述
我需要使用 IF
创建一个新列.
I need to create a new column with an IF
.
如果两个日期之间的差额超过一个月,则必须使用类似文本的多时",但如果不是,则必须显示日期.
If the difference between two dates is more than a month I have to use a text-like "much time" but if it is not I have to show a date.
因此,日期必须转换为字符串才能使用 text 列.如何将日期转换为文本?
So the date must be converted to a string to use a text column. How can I convert date to text?
Fecha_real =
IF( DATEDIFF(ventas[fecha_pedido]; ventas[fecha]; month) = 1 ;
"much time";
ConvertToTextInSomeWay ventas[fecha]
)
推荐答案
使用 FORMAT
函数..例如, FORMAT(ventas [fecha],"Short Date")
会将 fecha
转换为类似文本的"12/31/2018"
.
This is pretty simple with the FORMAT
function.. For example, FORMAT(ventas[fecha], "Short Date")
will convert fecha
into textlike "12/31/2018"
.
那只是一种格式示例.如果您愿意其他方法,则有很多预定义和自定义选项.例如, FORMAT(ventas [fecha],"dd-mm-yyyy")
会格式化与"31-12-2018"
相同的日期.
That's just one format example. There are plenty of pre-defined and custom options if you'd rather something else. For example, FORMAT(ventas[fecha], "dd-mm-yyyy")
would format that same date as "31-12-2018"
instead.
这篇关于如何创建将日期转换为文本的新列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!