Get complete CodeIgniter blog project for free!

Downloaded more than 161 times, this is full project must-study for serious developers!

By submitting this form, you agree to our Terms of Service and Privacy Policy.

Bangla date and time in PHP

Some developer asked me about Bangla date and time. A brother asked me “Is it possible to create Bangla date and time?” I replied him “Sure why not?” php provides us all type facilities we can create any future as we wish. We can create Bangla date and time using php. Today I am going to show you how to create Bangla date and time. This code is originally created by Tareq Hasan. This is the main function of the script. first, create a file name as bnTime.php and write down this code into this file.

<?php
class BanglaDate {
private $timestamp;
private $morning;
private $engHour;
private $engDate;
private $engMonth;
private $engYear;
private $bangDate;
private $bangMonth;
private $bangYear;
private $bn_months = array("???", "???", "???????", "?????", "?????", "???????", "?????", "??????", "?????", "??????", "???????", "?????????");
private $bn_month_dates = array(30,30,30,30,31,31,31,31,31,30,30,30);
private $bn_month_middate = array(13,12,14,13,14,14,15,15,15,15,14,14);
private $lipyearindex = 3;
function __construct( $timestamp, $hour = 6 ) {
$this->BanglaDate( $timestamp, $hour );
}
function BanglaDate( $timestamp, $hour = 6 ) {
$this->engDate = date( 'd', $timestamp );
$this->engMonth = date( 'm', $timestamp );
$this->engYear = date( 'Y', $timestamp );
$this->morning = $hour;
$this->engHour = date( 'G', $timestamp );
//calculate the bangla date
$this->calculate_date();
//now call calculate_year for setting the bangla year
$this->calculate_year();
//convert english numbers to Bangla
$this->convert();
}
function set_time( $timestamp, $hour = 6 ) {
$this->BanglaDate( $timestamp, $hour );
}
private function calculate_date() {
$this->bangDate = $this->engDate - $this->bn_month_middate[$this->engMonth - 1];
if ($this->engHour < $this->morning)
$this->bangDate -= 1;

if (($this->engDate <= $this->bn_month_middate[$this->engMonth - 1]) || ($this->engDate == $this->bn_month_middate[$this->engMonth - 1] + 1 && $this->engHour < $this->morning) ) {
$this->bangDate += $this->bn_month_dates[$this->engMonth - 1];
if ($this->is_leapyear() && $this->lipyearindex == $this->engMonth)
$this->bangDate += 1;
$this->bangMonth = $this->bn_months[$this->engMonth - 1];
}
else{
$this->bangMonth = $this->bn_months[($this->engMonth)%12];
}
}
function is_leapyear() {
if ( $this->engYear % 400 == 0 || ($this->engYear % 100 != 0 && $this->engYear % 4 == 0) )
return true;
else
return false;
}
function calculate_year() {
$this->bangYear = $this->engYear - 593;
if (($this->engMonth < 4) || (($this->engMonth == 4) && (($this->engDate < 14) || ($this->engDate == 14 && $this->engHour < $this->morning))))
$this->bangYear -= 1;
}
function bangla_number( $int ) {
$engNumber = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 0);
$bangNumber = array('?', '?', '?', '?', '?', '?', '?', '?', '?', '?');
$converted = str_replace( $engNumber, $bangNumber, $int );
return $converted;
}
function convert() {
$this->bangDate = $this->bangla_number( $this->bangDate );
$this->bangYear = $this->bangla_number( $this->bangYear );
}
function get_date() {
return array($this->bangDate, $this->bangMonth, $this->bangYear);
}
}
function BDdate($time)
{
$bn = new BanglaDate($time);
$output = $bn->get_date();
$ReadyDate = "$output[0] $output[1] $output[2]";
return $ReadyDate;
}
?>
We have created our function successfully now this is fully ready for use. Let’s see how we run this. We are going to create a new file name as index.php and write down this code
index.php

<?php
include('bnTime.php');
$time = time();
$Bdate = BDdate($time);
echo $Bdate;
?>
Now run this script into your server this server will execute Bangla date and time. I hope this article is helpful for you. If you have any question about this article you can comment bellow this article.






Search on PHPAns
Subscribe to PHPAns
Join with our 32000+ subscribers and get our latest articles in your email inbox for free.
Delivered by FeedBurner
We always respect your privacy and take protecting it seriously.
Connect Social With PHPAns
Top