The aim of this project is to make it more easier for developers to work with jalali (shamsi - شمسی) dates.
- Support .Net Date and Time Formatting (More Information at this page: Custom Date and Time Format Strings ).
- Developed with C# (SQL CLR)
-
Make sure you have .NET framework 4.7.2+ installed on your server.
-
Since this library has beed developed using SQL CLR, firstly you need to configure your SQL Server by Enabling CLR Integration In SQL Server
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'clr enabled', 1;
GO
RECONFIGURE;
GO
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'clr enabled', 1;
GO
EXEC sp_configure 'clr strict security',0;
GO
RECONFIGURE;
GO
-
Run the Deployment Script in SQL Server Management Studio to generate the Jalali functions in your database.
-
Note that you have to run this script in SQLCMD Mode. So in SQL Management Studio, Select Query Menu, and then select SQLCMD Mode. Now you will be able to execute the query.
-
Please be sure that you have changed the [your-database-name] inside the Deployment Script to your database's name.
Suppose that GETDATE() Method in sql server returns 2016/09/22 15:04:33
select dbo.GregorianToJalali(GETDATE(),'yy') -- returns 95
select dbo.GregorianToJalali(GETDATE(),'yyyy') -- returns 1395
select dbo.GregorianToJalali(GETDATE(),'yyyy-MM') -- returns 1395-07
select dbo.GregorianToJalali(GETDATE(),'yyyy-M') -- returns 1395-7
select dbo.GregorianToJalali(GETDATE(),'yyyy/MM/dd') -- returns 1395/07/01
select dbo.GregorianToJalali(GETDATE(),'yyyy/MM/dd hh:mm tt') -- returns 1395/07/01 03:04 ب ظ
select dbo.GregorianToJalali(GETDATE(),'yyyy/MM/dd hh:mm:ss tt') -- returns 1395/07/01 03:04:33 ب ظ
select dbo.GregorianToJalali(GETDATE(),'yyyy/MM/dd HH:mm') -- returns 1395/07/01 15:04
select dbo.GregorianToJalali(GETDATE(),'yyyy MMMM dddd') -- returns 1395 پنج شنبه مهر
select dbo.JalaliToGregorian('95-06-11','-') --returns 2016-09-01 00:00:00.000
select dbo.JalaliToGregorian('1395/06/11','/') --returns 2016-09-01 00:00:00.000
★ Some times you need to have the first and last day of a persian month in gregorian date (specially in reporting)
select dbo.GetJalaliLastDayOfMonth(GETDATE()) --returns 2016-10-21 00:00:00.000 which is equal to 1395/07/30
select dbo.GetJalaliFirstDayOfMonth(GETDATE()) --returns 2016-09-22 00:00:00.000 which is equal to 1395/07/01