使用Postgres将Excel日期格式转换为常规日期 [英] Convert Excel date format to regular date with postgres

查看:153
本文介绍了使用Postgres将Excel日期格式转换为常规日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将csv文件加载到DBeaver postgres数据库中,日期表示为5位数字.(41827、35267、39444等)我知道这些格式在Excel中的格式为自1900年1月1日以来的天数.是否可以在编辑器中编写查询以将其转换为mm/dd/yyyy?

I have csv files loaded into a DBeaver postgres database with the dates expressed as 5 digits. (41827, 35267, 39444, etc.) I know these are formatted in Excel as the number of days since Jan 1, 1900. Is there a query I can write in my editor to convert those into a mm/dd/yyyy?

我尝试使用SELECT/INTERVAL/CAST类型的函数,但无法完全弄清语法.

I've tried using a SELECT/INTERVAL/CAST type of function but cant quite figure out the syntax.

示例:架构:配置文件,表:account_transactions,列名:date_activated,单元格值:41827(varchar)

Example: Schema: profiles, Table: account_transactions, Column name: date_activated, Cell value: 41827(varchar)

推荐答案

Excel日期代表自1899年12月30日以来的天数(大概,这是错误的-早期年份不准确).

Excel dates represent the number of days since December 30th, 1899 (well, approximatly - early years are inaccurate).

在Postgres中,您可以执行以下操作:

In Postgres you could do:

date '1899-12-30' + myexceldate::int * interval '1' day

其中 myexceldate 是包含Excel编号的文本列的名称.

Where myexceldate is the name of the text column that holds the excel number.

这篇关于使用Postgres将Excel日期格式转换为常规日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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