有没有办法用 Postgres 存储阿拉伯日期?

发布于 2024-12-10 01:17:01 字数 204 浏览 0 评论 0原文

我是一名 PHP 开发人员,正在开发一个项目,需要在数据库中存储阿拉伯日期。

不过,我已经创建了该应用程序并在其中嵌入了 JavaScript 阿拉伯日历。

现在,当我选择一个日期(例如 12/02/1442)并按下“保存”按钮时,会出现以下错误:

Year Out Of Range

I am a PHP developer and I am working on a project in which I need to store Arabic dates in my database.

However, I have created the application and embedded a JavaScript Arabic calender in it.

Now when I select a date, e.g 12/02/1442, and press the save button, it gives me the following error:

Year Out Of Range

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

囍孤女 2024-12-17 01:17:01

这些日期(阿拉伯语、Jalali 等)通常会出现 SQL 服务器问题。根据我的经验,有 3 种方法可以处理它:

  1. 使用字符类型将日期存储到具有任何自定义格式的字段中。 (问题是:操作、算术、排序……它们很难实现)

  2. 使用整数固定字符类型来存储日期,例如<代码>14420101代表1/1/1442。 (与第一个相同,但解决了排序问题)

  3. 使用datetimestamp类型存储,应将日期转换为标准日期格式后再存储到数据库中,当你阅读它们时将它们转换回来。该方法需要外部编程语言来处理(通常有外部语言)。或者您可以在数据库中编写内部函数。

只需存储日期然后方法 1 和 2 就足够了。

否则,我建议使用第三种方法,因为您可以使用数据库服务器或编程语言中存在的datetime预定义函数。

例如,您可以在 PHP 中轻松使用 date_diff(),或者使用 postgres 内部函数来处理日期。

These dates (Arabic, Jalali, ...) usually have problems with SQL servers. In my experience, there are 3 ways to handle it:

  1. Using character types for storing dates into the fields with any custom format. (The problem are: Manipulating, arithmetic, sorting,... which they are hard to implement)

  2. Using integer or fixed character type for storing dates, like 14420101 for 1/1/1442. (Same as first one, but sorting is solved)

  3. Using date or timestamp type for storing, you should convert dates to standard date format before storing it into the database, and when you're reading them convert them back. This method needs a external programming language to handle (Usually there is an external language). Or you can write a internal functions in your database.

Just storing dates then methods 1 and 2 are enough.

Otherwise, I suggest third approach, because you can use date and time pre-defined functions which exists in database servers or programming languages.

For example you can use date_diff() easily in PHP, or use postgres internal functions for dates.

浅忆流年 2024-12-17 01:17:01

我认为这将是编写自定义数据类型的完美应用程序。也许有人已经做到了,或者你可以开始。

I think this would be a perfect application to write a custom data type. Maybe someone has already done it, or you could start.

一瞬间的火花 2024-12-17 01:17:01

PostgreSQL 支持以 Julian Day 形式输入和输出日期和时间戳。手册中的两个相应部分:

如果您想在数据库中进行计算,这可能会有所帮助。如果这不是问题,只需按照 Masoud M. 的建议存储日期即可。

PostgreSQL supports input and output of dates and timestamps as Julian Day. The two appropriate sections in the manual:

That might help if you want to do calculations in the database. If that's not an issue, just store the dates as Masoud M. has suggested.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文