Click here to Skip to main content
15,861,168 members
Articles / Programming Languages / PHP

Persian Calendar in PHP

Rate me:
Please Sign up or sign in to vote.
5.00/5 (15 votes)
17 Sep 2008CPOL2 min read 79.6K   3.8K   14   13
Generates Persian Calendar

Introduction

With this PHP script, you can generate Persian Calendar PHP easily.

Background

This script was created by Jalali and I just modified it and submit it here.

Using the Code

Persian calendar functions:
PHP
function mds_date($format, $when="now", $persianNumber = 0) 

parameters:

  • $format: Format of ouput date
  • $when: Time of calendar into the second, if it sets "now", the mds_date function shows current date
  • $persianNumber: If you want to print numbers into the Persian numbers, set it to 1 else set it to zero

returns:

  • string of solar date

Sample:

PHP
<?php
require_once("PersianCalendar.php");

echo mds_date("Y/m/d", "now", 1); // ۱۳۸۲/۰۸/۰۵
echo mds_date("l j F Y";, make_time(0,0,0,6,30,1998), 1); //پنجشنبه ۱۱ دي ۱۳۴۸
echo mds_date("l j F Y , i : H", time(), 0); //سه شنبه 15 مرداد 1387 , 20 : 07
?>
فرمتخروجیمثال
A قبل‏ازظهر و یا بعدازظهر را نشان می دهد قبل‏ازظهر - بعدازظهر
a ق.ظ و یا ب.ظ را نشان می دهد ق.ظ - ب.ظ
d چندمین روز از ماه را به صورت عدد دورقمی 01 - 02 - 03 - ... -31
D نام روز هفته را با یک کلمه ی - د - ... - ج
F نام کامل ماه فروردین - اردیبهشت - ... - اسفتد
g نمایش ساعت به صورت 12 ساعته 1 - 2 - 3 - ... - 12
G نمایش ساعت به صورت 24 ساعته 0 - 1 - 2 - ... - 23
h نمایش ساعت به صورت 12 ساعته دورقمی 01 - 02 - ... - 12
H نمایش ساعت به صورت 24 ساعته دو رقمی 00 - 01 - 02 - ... - 23
i نمایش دقیقه 00 - 01 - 02 - ... - 59
l(lower L) نمایش روزهای ماه به صورت عدد 1 - 2 - ... - 12
m نمایش ماه به صورت عدد دورقمی 01 - 02 - ... - 12
n نمایش ماه به صورت عدد 0 - 1 - 2 - ... - 12
s نمایش ثانیه یک دقیقه 01 - 02 - ... - 59
t تعداد روزها مشخص شده ماه (خورشیدی) 29
w چندمین روز هفته به صورت یک عدد تک رقمی 0(یکشنبه) - 1 - 2 - ... - 6
y نمایش سال به صورت عدد دورقمی 81 - 82 - ...
Y نمایش سال به صورت عدد چهار رقمی 1381 - 1382 - 1383 - ...
PHP
function make_time($hour="", $minute="", $second="", $Dmonth="" , $Dday="", $Dyear="")

This function is like mktime function in PHP.

parameters:

  • $hour: The number of the hour
  • $minute: The number of the minute
  • $second: The number of seconds past the minute
  • $Dmonth: The number of the month (in solar calendar) ( $Dmonth <= 11)
  • $Dmonth: The number of the month (in solar calendar)
  • $Dyear: The number of the month (in solar calendar)

returns:

  • The Unix timestamp corresponding to the arguments given

Sample:

PHP
<?php
require_once("PersianCalendar.php");

echo make_time(59, 59, 23, 11, 18, 1380); // 1013255963
echo make_time(80, 110, 54, 10, 60, 1362); //446291454
?>

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

 
Questionchange time zone Pin
alfered19436-Jan-20 21:41
alfered19436-Jan-20 21:41 
Questionfirst of all thats great Pin
Member 1470226729-Dec-19 2:48
Member 1470226729-Dec-19 2:48 
QuestionSupport for older dates Pin
Masood Hosseini15-Sep-14 22:53
Masood Hosseini15-Sep-14 22:53 
AnswerRe: Support for older dates Pin
Mohammad Dayyan15-Sep-14 23:35
Mohammad Dayyan15-Sep-14 23:35 
QuestionStoring date in MySQL Pin
Member 109944475-Aug-14 21:13
Member 109944475-Aug-14 21:13 
AnswerRe: Storing date in MySQL Pin
Mohammad Dayyan5-Aug-14 22:25
Mohammad Dayyan5-Aug-14 22:25 
GeneralThanks Pin
admiral59x13-Jun-14 2:12
admiral59x13-Jun-14 2:12 
QuestionMaking a library for CodeIgniter Pin
Mostafa Talebi14-Nov-13 10:22
Mostafa Talebi14-Nov-13 10:22 
AnswerRe: Making a library for CodeIgniter Pin
Mohammad Dayyan14-Nov-13 10:26
Mohammad Dayyan14-Nov-13 10:26 
GeneralMy vote of 5 Pin
ghandon.211015-Apr-13 21:52
ghandon.211015-Apr-13 21:52 
QuestionI guss here is a problem Pin
mahboobehkhorram6-Mar-12 1:36
mahboobehkhorram6-Mar-12 1:36 
AnswerRe: I guss here is a problem Pin
Mohammad Dayyan6-Mar-12 1:55
Mohammad Dayyan6-Mar-12 1:55 
GeneralAfarin Pin
SaeedM24-Oct-08 14:17
SaeedM24-Oct-08 14:17 

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.