Click here to Skip to main content
15,890,438 members
Articles / Web Development / HTML

Bootstrap Persian DateTimePicker

Rate me:
Please Sign up or sign in to vote.
4.96/5 (53 votes)
10 Oct 2015CPOL2 min read 375.6K   18.6K   20   112
MdPersianDateTime is a jQuery plugin to create Persian DateTimePicker with bootstrap popover

Image 1

This Article moved to https://github.com/Mds92/MD.BootstrapPersianDateTimePicker, to download new versions see that.

Introduction

If you are looking for a jquery plugin Persian DateTimePicker with bootstrap, MdPersianDateTime is that it.
This plugin use bootstrap popover to show Persian DateTimePicker. so it has flexibility of bootstrap's popover.

Features

  • Use both javascript code or html tag attributes to run.
  • Changing placement as bootstrap's popover
  • Use target selector to show DateTimePicker on an element and change another element value
  • Ability to switch between DateTimePicker and DatePicker, you can disable TimePicker
  • From date, To date filter.

Using the code

Installing this library by nuget:

Install-Package MD.BootstrapPersianDateTimePicker

At first add the references to your html file:
Order of tags are important

XML
<head>
	<meta charset="utf-8" />	
	<link rel="stylesheet" href="bootstrap.min.css" />
	<link rel="stylesheet" href="bootstrap-theme.min.css" />
	<link rel="stylesheet" href="jquery.Bootstrap-PersianDateTimePicker.css" />

    <script type="text/javascript" src="jquery-2.1.1.js"> </script>
    <script type="text/javascript" src="bootstrap.min.js"> </script>	
</head>
.
.
.
<body>

	<script src="calendar.js" type="text/javascript"></script>
    <script src="jquery.Bootstrap-PersianDateTimePicker.js" type="text/javascript"></script>
</body>

There are two approaches to use MdPersianDateTime

1. Use JavaScript and jQuery as another jQuery's plugins

You can use the folowing settings for this approach (you can omit them, so the plugin use the default values).

  • Placement string to determine popover placement.It's equals with bootstrap's popover placement. So it can be 'bottom', 'right', 'left', 'top'
  • Trigger string to determine the trigger of bootstrap popover to show DateTimePicker. like 'focus', 'click', 'mouseover', ...
  • EnableTimePicker boolean enables TimePicker on the html element's DateTimePicker. default is true
  • TargetSelector string determines the jQuery selector of the element to write the DateTime string into it.
  • GroupId string determines the group name in FromDate, ToDate filtering. you have to use this attribute if you wanna use the filter
  • ToDate boolean determines the html tags as ToDate filter.
  • FromDate boolean determines the html tags as FromDate filter

Sample :

 

JavaScript
<script type="text/javascript">
    $('#textBoxInputId').MdPersianDateTimePicker({
        Placement: 'bottom', // default is 'bottom'
        Trigger: 'focus', // default is 'focus',
	EnableTimePicker: true, // default is true,
	TargetSelector: '', // default is empty,
	GroupId: '', // default is empty,
	ToDate: false, // default is false,
	FromDate: false, // default is false,
    });
</script>

2. Use html tags attributes.

In this approach you can determine the settings with the following attributes:

data-DateTimePicker="true"
data-Placement="bottom"
data-Trigger="focus"
data-EnableTimePicker="true"
data-TargetSelector="#fromDate1"
data-GroupId="group1"
data-ToDate="true"
data-FromDate="true"

Sample :

HTML
<button class="btn btn-default" data-MdDateTimePicker="true" data-TargetSelector="#input1" data-EnableTimePicker="true" data-Placement="left" data-Trigger="click">انتخاب تاریخ</button>

Convert to .NET DateTime

If you gonna to parse the generated DateTime string with this DateTimePicker in .Net and convert it to DateTime you can use the following library easily.

Image 2 Persian Calendar(PersianDateTime) in C#

History

  • 30th December 2014: First Post
  • 31th December 2014: Year dropdown and month dropdown added. 
  • 4th January 2015: fix a bug in date range
  • 10th June 2015: fix a bug in displaying days
  • 22th June 2015: fix a bug in displaying days
  • 7th Septambar 2015: fix a bug in changing textbox event
  • 11th October 2015: fix some bug and adding some features and moved the source code to github

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Iran (Islamic Republic of) Iran (Islamic Republic of)
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
AnswerRe: change calendar display format Pin
Mohammad Dayyan5-Jan-16 0:43
Mohammad Dayyan5-Jan-16 0:43 
Questionتغییر تم Pin
Member 1000240710-Sep-15 7:55
Member 1000240710-Sep-15 7:55 
AnswerRe: تغییر تم Pin
Mohammad Dayyan11-Sep-15 19:20
Mohammad Dayyan11-Sep-15 19:20 
GeneralRe: تغییر تم Pin
Member 1000240713-Sep-15 8:12
Member 1000240713-Sep-15 8:12 
Questionتغییر تم Pin
Member 1000240710-Sep-15 7:55
Member 1000240710-Sep-15 7:55 
AnswerRe: تغییر تم Pin
Mohammad Dayyan5-Jan-16 0:47
Mohammad Dayyan5-Jan-16 0:47 
Questionافزودن mask Pin
Hadi Zaker10-Sep-15 4:19
Hadi Zaker10-Sep-15 4:19 
AnswerRe: افزودن mask Pin
Mohammad Dayyan11-Sep-15 19:22
Mohammad Dayyan11-Sep-15 19:22 
سلام
مسک خودش یه پلاگین جدا هست که شما میتونید اونو به این تکس باکس ها اضافه کنید
فعلا قصد اضافه کردن مسک رو ندارم
Generalخیلی ممنون و متشکر Pin
ehsabd7-Sep-15 21:47
ehsabd7-Sep-15 21:47 
GeneralRe: خیلی ممنون و متشکر Pin
Mohammad Dayyan10-Sep-15 6:13
Mohammad Dayyan10-Sep-15 6:13 
BugWon't work for the second time Pin
Sepehr Mohammad7-Sep-15 6:15
Sepehr Mohammad7-Sep-15 6:15 
GeneralRe: Won't work for the second time Pin
Mohammad Dayyan10-Sep-15 6:24
Mohammad Dayyan10-Sep-15 6:24 
Questionhow change display Farsi number to English numbers? Pin
SalmanSamian2-Sep-15 20:22
SalmanSamian2-Sep-15 20:22 
AnswerRe: how change display Farsi number to English numbers? Pin
Mohammad Dayyan4-Sep-15 8:57
Mohammad Dayyan4-Sep-15 8:57 
AnswerRe: how change display Farsi number to English numbers? Pin
Mohammad Dayyan6-Sep-15 10:31
Mohammad Dayyan6-Sep-15 10:31 
GeneralRe: how change display Farsi number to English numbers? Pin
SalmanSamian6-Sep-15 19:33
SalmanSamian6-Sep-15 19:33 
GeneralRe: how change display Farsi number to English numbers? Pin
Mohammad Dayyan11-Sep-15 19:30
Mohammad Dayyan11-Sep-15 19:30 
GeneralRe: how change display Farsi number to English numbers? Pin
Member 1197738213-Sep-15 1:13
Member 1197738213-Sep-15 1:13 
GeneralRe: how change display Farsi number to English numbers? Pin
Mohammad Dayyan15-Sep-15 21:43
Mohammad Dayyan15-Sep-15 21:43 
Questionنمایش در زیر پنجره bootstrap modal Pin
MBahr1-Sep-15 9:00
MBahr1-Sep-15 9:00 
AnswerRe: نمایش در زیر پنجره bootstrap modal Pin
Mohammad Dayyan1-Sep-15 18:12
Mohammad Dayyan1-Sep-15 18:12 
Questionغیر فعال کردن تاریخهای مورد نظر Pin
khobyari27-Jun-15 17:53
khobyari27-Jun-15 17:53 
AnswerRe: غیر فعال کردن تاریخهای مورد نظر Pin
Mohammad Dayyan29-Jun-15 21:35
Mohammad Dayyan29-Jun-15 21:35 
GeneralRe: غیر فعال کردن تاریخهای مورد نظر Pin
khobyari30-Jun-15 1:08
khobyari30-Jun-15 1:08 
Questionمن نمیتونم اجراش کنم Pin
Ali.shariati99023-Jun-15 4:14
Ali.shariati99023-Jun-15 4:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.