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
PostgreSQL uses the yyyy-mm-dd format for storing and inserting date values. If you create a table that has a DATE column and you want to use the current date as the default value for the column, you can use the CURRENT_DATE after the DEFAULT keyword.
The timestamptz datatype is a time zone-aware date and time data type. PostgreSQL stores the timestamptz in UTC value.
Postgres DATE data type Postgres uses the DATE data type for storing different dates in YYYY-MM-DD format. It uses 4 bytes for storing a date value in a column. You can design a Postgres table with a DATE column and use the keyword DEFAULT CURRENT_DATE to use the current system date as the default value in this column.
First we create a table that has both timestamp and timestamptz columns using the below command: CREATE TABLE timestamp_demo (ts TIMESTAMP, tstz TIMESTAMPTZ); Then we will set the time zone of database server to Asia/Calcutta as below: SET timezone = 'Asia/Calcutta';
These 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
for 1/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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With