如何格式化kdb中的日期列 [英] how to format date column in kdb

查看:85
本文介绍了如何格式化kdb中的日期列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是KDB的新手.我有一个查询的KDB表:

I am newbie to KDB. I have a KDB table which I am querying as:

select[100] from table_name

现在此表中有一些日期列,这些日期的日期以这种格式存储

now this table has got some date columns which have dates stored in this format

yyyy.mm.dd

yyyy.mm.dd

我希望查询该表并以特定格式(例如mm/dd/yyyy)检索日期字段.如果这将是其他任何RDBMS表,这就是我要做的事情:
select to_date(date_field,'mm/dd/yyyy') from table_name
我需要以上的kdb等效项.我已经尽力通过kdb docs,但是无法找到任何函数/示例/语法来做到这一点. 预先感谢!

I wish to query that table and retrieve the date fields in specific format (like mm/dd/yyyy). If this would've been any other RDBMS table this is what i would have done:
select to_date(date_field,'mm/dd/yyyy') from table_name
I need kdb equivalent of above. I've tried my best to go through the kdb docs but unable to find any function / example / syntax to do that. Thanks in advance!

推荐答案

我不认为KDB具有内置的日期格式设置功能. 最可靠的方法是自己格式化日期. 例如

I don't think KDB has built-in date formatting features. The most reliable way is to format date by yourself. For example

t: ([]date: 10?.z.d);
update dateFormatted: {x: "." vs x; x[1],"/",x[2],"/",x[0]} each string date from t

给予

date       dateFormatted
------------------------
2012.07.21 "07/21/2012"
2001.05.11 "05/11/2001"
2008.04.25 "04/25/2008"
....

或者,更有效的格式设置方法是

Or, more efficient way to do the same formatting is

update dateFormatted: "/"sv/:("."vs/:string date)[;1 2 0] from t

这篇关于如何格式化kdb中的日期列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆