This project provides a set of custom SQL functions for MariaDB to handle operations related to the Persian calendar (Jalali calendar) and Julian day conversions. These functions are ideal for projects requiring advanced date and time computations with Persian dates.
jdate2timestampβ Converts a Jalali date to a Unix timestamp.timestamp2jdatetimeβ Converts a Unix timestamp to a Jalali datetime string.timestamp2jdateβ Converts a Unix timestamp to a Jalali date string.jleapβ Checks if a Jalali year is a leap year.
DateToJulianDayβ Converts a Gregorian date to a Julian Day.AddTimeToJulianDayβ Adds time (hours, minutes, seconds) to a Julian Day.GetHoursOfJulianDay,GetMinutesOfJulianDay,GetSecondsOfJulianDayβ Extracts hours, minutes, and seconds from a Julian Day.GetTimeOfJulianDayβ Returns the time portion of a Julian Day as a string.JulianDayToDateβ Converts a Julian Day to a Gregorian date.JulianDayToTimestampβ Converts a Julian Day to a Unix timestamp.JulianDayWithoutTimeβ Removes the time portion from a Julian Day.TimestampToJulianDayβ Converts a Unix timestamp to a Julian Day.
JDateβ Returns a formatted Jalali date string.JDay,JMonth,JYearβ Extracts the day, month, and year from a Jalali date.JMonthNameβ Returns the name of the Jalali month.
Ensure that you are using MariaDB as your database engine.
- Open your terminal and connect to your MariaDB instance:
mysql -u [username] -p
- Import the SQL file:
πΉ Replace
source /path/to/pasoonate-mariadb.sql;
/path/to/with the correct file path.
You can now call the functions in your SQL queries:
-- Convert a Unix timestamp to a Jalali datetime
SELECT timestamp2jdatetime(1700000000);
-- Convert a Jalali date to a Unix timestamp
SELECT jdate2timestamp(1402, 10, 29, 15, 30, 0);
-- Convert a Unix timestamp to a Jalali date
SELECT timestamp2jdate(1672531199);
-- Check if a Jalali year is a leap year
SELECT jleap(1402);
-- Convert a Gregorian date to a Julian Day
SELECT DateToJulianDay(2023, 1, 1, 0, 0, 0);SELECT timestamp2jdate(UNIX_TIMESTAMP('2023-01-01 00:00:00'));
-- Output: 1401/10/11
SELECT JMonthName('2023-01-01 00:00:00');
-- Output: Ψ―Ϋ
SELECT JulianDayToDate(2459945.5);
-- Output: 2023/1/1 0:0:0
SELECT jleap(1402);
-- Output: 0 (not a leap year)Contributions are welcome! Feel free to fork this repository and submit a pull request. π
This project is open-source and available under the MIT License.