Giter Club home page Giter Club logo

persiandate4mysql's Introduction

[MySQL] pDate

Content:

About

[MySQL] pDate is a Gregorian / Jalali date converter functions for MySQL.

Requirements

  • MySQL 5+

Download

Installation

Import pDate.sql in your database.

Usage

You can use these six functions, which are provided on a set:

PDATE(datetime)

Takes georgian datetime as input and returns jalali date in text format.

PMONTH(datetime)

Takes georgian datetime as input and returns jalali month number in text format.

PMONTHNAME(datetime)

Takes georgian datetime as input and returns jalali month name in text format.

PYEAR(datetime)

Takes georgian datetime as input and returns jalali year number in text format.

PDAY(datetime)

Takes georgian datetime as input and returns jalali day number in text format.

GDATE(year smallint, month smallint, day smallint)

Takes jalali date in "year/month/day" format as input and returns georgian date in datetime format.

GDATESTR(jdate char(10))

Takes jalali date in string format (e.g: '1390/3/3' or '1390/03/3' or '1390/3/03 or '1390/03/03' ) as input and returns georgian date in datetime format.

You can not enter Jalali year in short format! for example '90/03/03' shows the 90th Jalali year, not 1390!


Here is simple line of sql code which you can use it to test the set of functions:

SELECT	pdate(NOW()),
		pyear('2009-09-22'),
        pmonth('2009-09-22'),
        pmonthname(NOW()),
        gdate(1366,9,19),
        gdatestr('1366/9/19');

License

GNU General Public License. http://www.gnu.org/licenses/gpl.txt

Issues/Feedbacks

https://github.com/zoghal/Presian-Date-for-MySQL/issues

persiandate4mysql's People

Contributors

amnkh avatar mahmoud-eskandari avatar mehdi-hp avatar nimah79 avatar saeidzebardast avatar sallar avatar spitmaan avatar yousha avatar youshaaleayoub avatar zoghal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

persiandate4mysql's Issues

مشکل در خروجی کوئری

سلام یک مشکل دراجرای کوئری زیر هستش :

SELECT DATE_FORMAT(PDATE("2022-05-20 19:12:21") , "%Y-%m-%d");

که در اینجا خروجی null برمیگردونه که اشتباه هستش باید 20-05-2022 باشه

غلط املایی در عنوان پروژه

@zoghal

سلام @zoghal عزیز
بعد از سال ها فرصتی شد تا به این پروژه برگردم. اولین چیزی که نظرم رو جلب کرد یه غلط املایی ریز در عنوان پروژه بود
واژه Presian باید به Persian تبدیل بشه
خیلی جالبه که چنین چیزی سال ها از نظر ها غایب مونده البته این قضیه چیز جدیدی نیست و بسیار اتفاق میافته.

من دسترسی لازم رو برای تفییر نام پروژه ندارم. امیدوارم تغییر نام امکان پذیر باشه و تاثیری بر روی فورک ها پروژه نداشته باشه
همینطور فکر کنم پیدا کردن پروژه رو در گوگل راحت تر بکنه.

Presian-Date-for-MySQL --> Persian-Date-for-MySQL

Finished - Unsuccessfully

[Err] 1418 - This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you might want to use the less safe log_bin_trust_function_creators variable)
[Err] CREATE DEFINER=root@localhost FUNCTION __mydiv(a int, b int) RETURNS bigint(20)
BEGIN

return FLOOR(a / b);

END;

Msg: Finished - Unsuccessfully

استخراج روزهای هفته از تاریخ

سلام .روزتون به خیر
ممنون از زحماتتون .از کد شما استفاده کردم و درست کار می کرد . فقط آیا می شه اسم روزهای هفته رو استخراج کرد ؟تاریخ رو بگیره بگه که کدوم روز از هفته س مثل شنبه ،یکشنبه … .
شاد و سر بلند باشید

مشکل در مرتب سازی تاریخ ها

سلام و درود
یک مشکل که برخوردیم بهش این هست که زمانی میخوایم گزارش ماهیانه بگیریم وقتی به ترتیب ماه گزارش رو مرتب سازی میکنیم بر اساس ماه های میلادی مرتب سازی میشه نه شمسی
مثلا ماه ده شمسی رو اول میاره
حکم چیه با این اوصاف ؟

مشکل در اضافه کردن به هاست اشتراکی

سلام ممنونم از شما بابت این کد ها
این کدها در لوکال کاملا درست کار میکنه ولی در هاست اشتراکی حین ایمپورت کردن با این مواجه میشم:

#1227 - Access denied; you need (at least one of) the SUPER privilege(s) for this operation

و طی تحقیقی که کردم فهمیدم باید این مورد رو از کد شما حذف کرد:

CREATE DEFINER=root@localhost

که متاسفانه این مورد هم کار نداد و این رو نشون میده حین ایمپورت:

Unrecognized statement type. (near "FUNCTION" at position 0)
Unrecognized statement type. (near "END" at position 194)

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FUNCTION __mydiv(a int, b int) RETURNS bigint(20)
BEGIN

Copyright (C) ' at line 1

ممنون میشم راهنمایی کنید

problem with extracting day or month

In the name of Allah,Salam,I had a problem while extracting day or month from query something like below ::
SELECT EXTRACT(
MONTH FROM pdate(
DATE( order_date_added ) )
) AS monthoforder, EXTRACT(
DAY FROM pdate(
DATE( order_date_added ) )
) AS dayoforder, COUNT( order_id ) AS num_orders, IFNULL( SUM( total_price ) , 0 ) AS daily_total, pdate(
DATE( order_date_added )
)
FROM (
orders
)
GROUP BY DATE( order_date_added )
ORDER BY orders.order_date_added DESC
LIMIT 10

Actually I was shown nothing

PersianSeason And weekNumber support

it would be more appreciated if 'pseason' and 'pseasonName' as well as weekNumber functions added to the script.
it can be implemented using (pmonth/4) for the season in simplest way.

مشکل در ایمپورت کردن

سلام
من سعی کردم ایمپورت کنم که با خطای زیر مواجه شدم
(بعد از اینکه دیتابیسمو انتخاب کردم از منوی ایمپورت فایلو ایمپورت کردم)
DELIMITER ; ;

CREATE DEFINER = root@localhost FUNCTION __mydiv (

a INT,
b INT
) RETURNS BIGINT( 20 ) BEGIN # Copyright (C) 2009-2012 Mohammad Saleh Souzanchi

WebLog : www.saleh.soozanchi.ir

Version V1.0.2

RETURN FLOOR( a / b ) ;

END ; ;

MySQL said: Documentation
#1418 - This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you might want to use the less safe log_bin_trust_function_creators variable)

Wrong Date Conversion

wrong calculate in below date "2030-03-20" as below :

pdate('2030-03-20') // Result : 1408-12-30

gdatestr('1408/12/29') // Result : 2030-03-20 00:00:00

one miladi date with two persian date result !

not optimized for Big queries

So so good functions and useful but if we have near 200,000 records the operation speed of "where" and "group by" decreased near about 0.001 of normal date.

تغییر تابع pdate

با سلام
من توی پروژه م احتیاج به این داشتم وقتی که از
substr
استفاده می کنم واسه ماه هایی که تک رقمی هستند حتما صفر قبل از عدد نمایش داده بشه
توی تابع
pdate
این تغییرات رو اعمال کردم

IF (jm < 10) THEN
	SET jm= CONCAT('0',jm);
END IF;

و نوع jm
رو هم
varchar
کردم، دوستانی که به مورد من برخورد کردن میتونن ازش استفاده کنن.

Problem with deterministic flags

Hi,
In new versions of MySQL and MariaDB running the SQL file creates this error for each function:

#1418 - This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)

When you create a stored function, you must declare either that it is deterministic or that it does not modify data. Otherwise, it may be unsafe for data recovery or replication.

By default, for a CREATE FUNCTION statement to be accepted, at least one of DETERMINISTIC, NO SQL, or READS SQL DATA must be specified explicitly. Otherwise, an error occurs:

To fix this issue add following lines After Return and Before Begin statement:

READS SQL DATA
DETERMINISTIC

For Example :

CREATE FUNCTION f2()
RETURNS CHAR(36) CHARACTER SET utf8
/*ADD HERE */
READS SQL DATA
DETERMINISTIC
BEGIN

This should be added to all functions, I modified it manually. Please update the main repo.
Thanks

امکان استفاده از توابع برای رشته اعداد فارسی در تاریخ

عرض سلام و احترام؛
برای استفاده از تابع GDATESTR - که تاریخ شمسی را به عنوان رشته (string) گرفته و مقدار تاریخ-زمان (datetime) میلادی را به عنوان خروجی تحویل می‌دهد - امکان استفاده از تاریخ فارسی وجود ندارد.
آیا راه حلی برای این مسئله وجود دارد؟

به عنوان مثال، وقتی از تابع به شکل زیر استفاده می‌کنیم، مشکلی ندارد و به درستی کار می‌کند:

SELECT gdatestr("1400/12/12");

اما وقتی همین رشته را به فارسی تحت عنوان آرگومان به تابع می‌دهیم، تابع به درستی کار نمی‌کند.

SELECT gdatestr("۱۴۰۰/۱۲/۱۲");

Installation error

SQL query:

DELIMITER ; ;

CREATE DEFINER = root@localhost FUNCTION __mydiv (
a int,
b int
) RETURNS bigint( 20 ) BEGIN
RETURN FLOOR( a / b ) ;

END ; ;

MySQL said: Documentation
#1418 - This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you might want to use the less safe log_bin_trust_function_creators variable)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.