Skip to content

Tareq Hasan

Posted on

Bangla date as a PHP class

I worked with Bangla date a long time ago. The first initiative was to make an extension for forum engine punBB. After that, I made a javascript widget to display Bangla date in any site. The third initiative was to make a facebook application that shows current Bangla date to your facebook profile.

I always wanted to publish this as a PHP Class but never got that chance to do so. After a long time I worked with Bangla date today and finally created a PHP Class to use it anywhere by anyone. Sorry for the late.

Usage:

<?php
include_once 'class.banglaDate.php';
$bn_date = new BanglaDate(time());
$date = $bn_date->get_date();
?>

You will get an array of converted date in Bangla.

A few things needed to know. Bangla date counted or changes after the sun rise. That means, where English date changes at 12’O clock at the night, Bangla date changes at the morning after the sunrise.

Class Constructor:
This class constructor has 2 parameters. The first one is timestamp and the second one is the hour of changing the date. If you want to change the Bangla date like English at 12’0 clock at the night, you should use $bn_date = new BanglaDate(time(), 0). But if you want to change the date at 6’O clock at the morning, use as $bn_date = new BanglaDate(time(), 6). If you don’t pass the second parameter, the default value is 6. Use as you like.

After Creating the class object, you can set another date using set_time() like $bn_date->set_time(time(), 4);

Fork on Github

40 thoughts on “Bangla date as a PHP class”

    1. হায় হায়, এখনি ঠিক করে দিচ্ছি। ধন্যবাদ জানানোর জন্যে

  1. when i use this class bangla fonts displayed as unknown Symbol.
    I use Font SolaimanLipi as unicode font . So how can i use ur class as unicode fonts.

  2. ভাই আজ তো ২৮ ফাল্গুন ১৪১৮ , কিন্তু এটা দেখায় ২৭ ফাল্গুন। লিপ-ইয়ারের জন্য কি সমস্যাটা হলো?
    ভাই দয়া করে এটা সমাধান করে দেন, আমি আপনার জাভাস্ক্রিপ্ট কোড টা ব্যবহার করি।

      1. অনেক ধন্যবাদ ভাই।
        আরেকটা সাহায্য চাইবো, আমি পিএইচপি কোডটা রান করালে এমন আসেঃ Array ( [0] => ২৮ [1] => ফাল্গুন [2] => ১৪১৮ )
        কিন্তু আপনারটা আসে এভাবেঃ document.write('আজ ২৮ ফাল্গুন ১৪১৮ বঙ্গাব্দ');

        document.write('আজ ২৮ ফাল্গুন ১৪১৮ বঙ্গাব্দ'); এভাবে আনতে হলে কি করতে হবে, যদি সময় হয় তাহলে একটু সাহায্য করবেন প্লিজ।

        1. ইয়াহু.........
          হয়ে গেছে ভাই, একটু অন্য ভাবে করেছি, এরের মাধ্যমে রিটার্ন না করে অন্য ভাবে করলাম, দারুন কাজ করছে।
          আবারো ধন্যবাদ এতো ভালো একটা কাজ ওপেন করে দেওয়ার জন্য।
          এখন থেকে আমি নিজের হোস্ট থেকেই বাংলা তারিখ দেখাতে পারবো......

  3. can you please tell how will i be able to print as "২৮ ফাল্গুন ১৪১৮" format NOT in a array like "Array ( [0] => ২৮ [1] => ফাল্গুন [2] => ১৪১৮ )"

    1. [php]$bn = new BanglaDate(time(), 0);
      $bdt = $bn->get_date();

      $text = sprintf( 'আজ %s', implode( ' ', $bdt ) );
      echo $text;[/php]

  4. Tareq vai,

    i used
    $bn = new BanglaDate(time(), 0);
    but the date still not changing at 12' o'clock

    can you help?

  5. Hello,

    I have a problem when i run this script in my IIS server.

    Here output screenshot: http://s10.postimg.org/oxr4o4nrt/sublime.png

    how can i solve this problem?

    my server config:
    OS: Windows 8
    Server IIS 8
    PHP Version: 5.4.13

    Please give me some solution.

    Thanks for this great work.

  6. Thank you very much for the class...
    I would like to know, how do I used bengali letter in web i mean integrate bangla into web site...

    I used unicode but not worked in Linux server...

    rgds, Mamun

  7. দারুন একটা পোষ্ট। তবে আমার একটা পিএইচপি নিউজ সাইটের জন্য ইংরেজী, বাংলা এবং আরবী তারিখ বাংলাতে দেখানো প্রয়োজন ছিল। সেজন্য আমি অনলাইনে আরো কিছু স্ক্রীপ্ট পেয়েছি। সেগুলোও দারুন কাজ করছে। যেমনঃ

  8. tareq bhai এক দিন বেশী হচ্ছে কেন? যেমন আজ ৪ বৈশাখ ১৪২১ দেখাচ্ছে কিন্তু আজ ৩রা বৈশাখ ১৪২১

  9. দয়া করে এই সাইট টা দেখলে আপনার তারিখের পার্থক্য বুঝতে পারবেন-
    http://www.kanchanmoni.com/baisakh.html

    1. কলকাতার বাংলা তারিখ আর বাংলাদেশের মধ্যে পার্থক্য আছে। বাংলা একাডেমির হিসাব অনুযায়ী বাংলা তারিখকে নির্দিষ্ট করে দেয়া হয়েছে, অপরদিকে কলকাতায় চাঁদের উপর ভিত্তি করে বাংলা তারিখ নির্ধারণ করা হয়। এখানেই গোলমাল পেকেছে।

  10. I had installed the Bangla date class and it was working perfectly. In the last few days it is displaying some characters like আজ ১৫ জ্যৈষ্ঠ১৪২১ বঙ্গাব্দ ( http://www.ettrika.com/ettrika-display.php ) . even the direct link http://tareq.wedevs.com/bangla_date_widget.php is displaying the same. I am using

    Also, Download Bangla Date Class above this page is not working. Could you please guide us. Is there a way to have the class and run it without direct URL link ?

  11. my result this
    বুধবার, 7 জানুয়ারি 2015, 8:30:11
    But i want to
    বুধবার, ৭ জানুয়ারী ২০১৫, ৮ঃ৩০ঃ১১
    thanks

    1. No problem using the code, but mentioning the link to the original code would help others to find out the source and the original author will be happy too :)

  12. I am showing bangla blog site post date(time_ago();)function but one problem only show 2 .i want to show bengle font that like(২)---plz help