把表中年和月两列整数拼成日期,为什么返回了空值
我在DolphinDB database GUI中执行下列代码:
tb=table(2001..2012 as yearOfRegistration,1..12 as monthOfRegistration)select string(yearOfRegistration) + "." + string(monthOfRegistration) + ".01" as newcat from tb
结果正常,如下:
但改成:
select date(string(yearOfRegistration) + "." + string(monthOfRegistration) + ".01") as newcat from tb
执行后结果如下图,看了下,月份是一位数的,都变成空值了,为啥?
回答
DolphinDB中DATE默认格式是yyyy.MM.dd,如2020.01.01,如不符合这个格式,需要用datetimeParse进行转换。代码改为如下:
select temporalParse(string(yearOfRegistration) + "." + string(monthOfRegistration) + ".01","yyyy.M.dd") as newcat from tb
或者从MONTH类型转换为DATE:
select date(1970.01M+(yearOfRegistration-1970)*12+monthOfRegistration-1) from tb
以上是 把表中年和月两列整数拼成日期,为什么返回了空值 的全部内容, 来源链接: utcz.com/a/36132.html