Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
481 views
in Technique[技术] by (71.8m points)

把表中年和月两列整数拼成日期,为什么返回了空值

我在DolphinDB database GUI中执行下列代码:

tb=table(2001..2012 as yearOfRegistration,1..12 as monthOfRegistration)
select string(yearOfRegistration) + "." + string(monthOfRegistration) + ".01" as newcat from tb

结果正常,如下:
image.png
但改成:

select date(string(yearOfRegistration) + "." + string(monthOfRegistration) + ".01") as newcat from tb

执行后结果如下图,看了下,月份是一位数的,都变成空值了,为啥?
image.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...