admin管理员组文章数量:1429455
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
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
Share
Improve this question
edited Oct 21, 2011 at 13:00
Jason Plank
2,3325 gold badges32 silver badges40 bronze badges
asked Oct 14, 2011 at 13:02
ScoRpionScoRpion
11.5k25 gold badges71 silver badges91 bronze badges
1
- 1 Please provide more info - code, DB schema, SQL statements etc. – Milen A. Radev Commented Oct 14, 2011 at 13:22
3 Answers
Reset to default 6These dates (Arabic, Jalali, ...) usually have problems with SQL servers. In my experience, there are 3 ways to handle it:
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)
Using integer or fixed character type for storing dates, like
14420101
for1/1/1442
. (Same as first one, but sorting is solved)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.
I think this would be a perfect application to write a custom data type. Maybe someone has already done it, or you could start.
PostgreSQL supports input and output of dates and timestamps as Julian Day. The two appropriate sections in the manual:
- http://www.postgresql/docs/9.1/interactive/functions-formatting.html
- http://www.postgresql/docs/9.1/interactive/functions-datetime.html
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.
本文标签: phpIs there a way to store Arabic dates with PostgresStack Overflow
版权声明:本文标题:php - Is there a way to store Arabic dates with Postgres? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745462007a2659365.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论