Code Monkey home page Code Monkey logo

sqlclr-jalali-date-utility's Introduction

SQL CLR Jalali Date Time Utility

The aim of this project is to make it more easier for developers to work with jalali (shamsi - شمسی) dates.

💡 Installation

  • 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

SQL Server 2005-2014

sp_configure 'show advanced options', 1;  
GO  
RECONFIGURE;  
GO  
sp_configure 'clr enabled', 1;  
GO
RECONFIGURE;  
GO  

SQL Server 2017+

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.

🕹 Usage

★ Convert Gregorian To Jalali:

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 پنج شنبه مهر
★ Convert Jajali Date To Gregorian:
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

sqlclr-jalali-date-utility's People

Contributors

mirsaeedi avatar

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.