[英]Convert Excel date format to regular date with postgres
I have csv files loaded into a DBeaver postgres database with the dates expressed as 5 digits.我将 csv 文件加载到 DBeaver postgres 数据库中,日期表示为 5 位数字。 (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? (41827、35267、39444 等)我知道这些在 Excel 中被格式化为自 1900 年 1 月 1 日以来的天数。是否可以在我的编辑器中编写查询以将它们转换为 mm/dd/yyyy?
I've tried using a SELECT/INTERVAL/CAST type of function but cant quite figure out the syntax.我试过使用 SELECT/INTERVAL/CAST 类型的函数,但无法弄清楚语法。
Example: Schema: profiles, Table: account_transactions, Column name: date_activated, Cell value: 41827(varchar)示例:架构:配置文件,表:account_transactions,列名:date_activated,单元格值:41827(varchar)
Excel dates represent the number of days since December 30th, 1899 (well, approximatly - early years are inaccurate). Excel 日期表示自 1899 年 12 月 30 日以来的天数(嗯,大约 - 早年是不准确的)。
In Postgres you could do:在 Postgres 中,您可以执行以下操作:
date '1899-12-30' + myexceldate::int * interval '1' day
Where myexceldate
is the name of the text column that holds the excel number.其中myexceldate
是保存 excel 编号的文本列的名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.