2018-11-09 Pujan Niroula 2 Minute(s) Read

Nepali Date [AD-BS] Converter in PHP

img-open source ad bs.png

If someone says I celebrate my birthday 3 times in a year then he must be lying or he must be Nepalicool. First birthday according to Bikram Sambat date, Second according to After Christ (AD) and third one according to tithi (Lunar Date) system. In this post I will discuss just about two date system and share Free AD-BS Converter in PHP. Because of government and society we must use BS date system and for internet we must use AD date system. Let's make it easy with this wonderful AD/BS converter.

Developing Nepali Date Converter Script

As I mentioned on my first post during daily new idea development period I thought to add multi date system in this So Called CMS. I googled and found desired converter but that has date limitation. If my grandfather want to convert his birthday then it will shows error. So I decided to write my own Nepali date converter in PHP for this blog. You can change date system and language of this blog from Site Setting.

It's completely based on arrays and date system of PHP. I have collected data from different sources. It's little boring to collect the correct data and use those data. I wrote it in very simple way based on counting days between dates. I thought it as most effective idea.

How to Use Nepali Date[ad/bs] Converter on Your Website?

Simply download and upload it to your server. Include it where you want to use. For eg. if you have to display it on index file and include it there and call for action... See my example below. If you want to display time too then use echo $date['l']; (Small L). and you can echo month name or month number by changing Case of $date['m']. Simply I can say you can use pretty same as date() function in PHP, 'm' means month number, 'M' mean month name etc...

How to store time on database for this converter?

It's simple just store time(). This function returns the current time in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).

How I Used This PHP Script?

I used it in very simple way. here is my code

$y = date('Y', time()); //Getting Year
$m = date('m', time()); //Getting Month
$d = date('d', time()); //Getting Day
require('nepali-date.php'); //Including library
$date = new nepali_date;
$date = $date->get_nepali_date($y, $m, $d);
echo $date['y'].'-'.$date['m'].'-'.$date['d']; //Printing Date

Lets describe it.
First I got current AD date (Year, Month and day). and called the class and this converter did rest and finally I print all dates.

Wishing Birthday on Nepali[B.S] Dates

If you own sites which is build for Nepali People then you want to wish them on Nepali Date but PHP doesn't support Bikram Sambat date system. Here you can use this to wish them. Store Nepali Date on database and Check today's date with this script. If month and date matched wish them. I have attached full code along with the script.

 Naming This

I almost forgot to name this item.laughing According to vedic astrology a famous astrologer suggested its name - Nepali Date Converter. tongue-out Further he added this name will be beneficial for SEO purpose too. Some astrologers suggested AD/BS date converter but According to market I thought the first one will be great.

Example

You can Check this free Online Nepali Date Converter based on this script.

 Thanks for reading... Glad to see you in comment section below.

Download Attached Files: Nepali Date Converter [Open Source].zip
Comments (35) Add New Comment
socratic2024-02-23 6:14 AM

Its like you read my mind! Yo? app?ar to know a ?ot about t?is, like ?ou wrote the book in it or s?mething. I think that you can do with some pics to drive the message home a bit, but instead of that, this is f?ntastic bl?g. An excellent read. I'll definitely ?e bac?.

Reply
ppc management London2024-02-21 7:48 AM

With havin so much content do you ever run into any problems of plagorism or copyright violation? My site has a lot of completely unique content I've either written myself or outsourced but it looks like a lot of it is popping it up all over the web without my authorization. Do you know any methods to help reduce content from being stolen? I'd definitely appreciate it.

Reply
sklep online2024-02-16 4:35 PM

What's Taking place i'm new to this, I stumbled upon this I've found It positively useful and it has aided me out loads. I am hoping to give a contribution & assist other customers like its helped me. Good job. You can see similar: sklep online and here sklep online

Reply
kosmetyki do skóry atopowej2024-02-16 1:04 PM

Very great post. I simply stumbled upon your blog and wanted to mention that I have really loved browsing your blog posts. In any case I will be subscribing in your rss feed and I'm hoping you write once more very soon!

Reply
sklep internetowy2024-02-15 12:40 AM

Can I simply say what a comfort to discover somebody who really understands what they're discussing on the internet. You definitely know how to bring a problem to light and make it important. More people really need to check this out and understand this side of your story. It's surprising you aren't more popular given that you definitely have the gift. I saw similar here: ecommerce and also here: dobry sklep

Reply
najlepszy sklep2024-02-14 7:27 AM

You could definitely see your skills in the article you write. The world hopes for even more passionate writers such as you who aren't afraid to mention how they believe. Always follow your heart. I saw similar here: dobry sklep and also here: sklep internetowy

Reply
ecommerce2024-02-14 1:30 AM

I've been surfing on-line greater than 3 hours lately, yet I by no means discovered any attention-grabbing article like yours. It's lovely value enough for me. Personally, if all website owners and bloggers made excellent content material as you did, the net will probably be a lot more useful than ever before.!

Reply
sklep internetowy2024-02-13 12:24 PM

It's very trouble-free to find out any matter on net as compared to books, as I found this paragraph at this site. I saw similar here: e-commerce and also here: najlepszy sklep

Reply
dobry sklep2024-02-13 7:05 AM

Your way of describing the whole thing in this piece of writing is in fact fastidious, all can without difficulty understand it, Thanks a lot. I saw similar here: sklep and also here: sklep online

Reply
sklep internetowy2024-02-12 11:16 PM

Thanks for sharing your thoughts. I truly appreciate your efforts and I am waiting for your next write ups thanks once again. I saw similar here: najlepszy sklep and also here: dobry sklep

Reply
shoponthe.top2024-02-08 11:43 PM

Wow, wonderful blog layout! How long have you ever been blogging for? you make running a blog glance easy. The full glance of your site is wonderful, as neatly as the content! You can see similar: Shoponthe.top and here Shoponthe.top

Reply
Ramesh2023-08-21 11:25 AM

Invalid Year range, when selected day 32 of the month

Reply
Laxman Adhikari2023-04-10 2:57 PM

hello i what to know how array of months is calculated .

Reply
Njn Khanal2022-11-19 7:51 AM

At first thank you so much for this, everything working well but when converting to nepali date month end like kartik 31 its showing mansir 1

Reply
Muniraj Rajbanshi2021-05-13 7:56 AM

How to get two digit year ?

Reply
Pujan Niroula2021-05-30 6:07 PM

No option, you can trim first two digit :) get your hands dirty

Sujan Stc2021-04-14 2:29 PM

If you are facing problem tallying nepali date and english date with 'Asia/Kathmandu' timezone, use timezone_open('UTC') on every date_create function like so: $date_start=date_create($this->firstday_en,timezone_open('UTC')); This will perfectly tally with english time and you dont have to change to UTC if your site is already using 'Asia/Kathmandu' timezone.

Reply
Pujan Niroula2021-05-30 6:08 PM

Thanks :)

Gopal Nepal2020-09-18 11:05 AM

Hello sir, I want to display format like this २०७७ असोज २ . But, find format for month not for year and day. How to do that ?

Reply
Pujan Niroula2020-09-29 2:59 AM

You can convert output date to devanagari Numbers with this function <?php function devanagari($num) { $num_nepali = array('०','१','२','३','४','५','६','७','८','९'); $num_eng = array('0','1','2','3','4','5','6','7','8','9'); $nums = str_replace($num_eng, $num_nepali, $num); return $nums; } echo devanagari('13905'); //Output १३९०५ ?>

John Doe2020-06-28 3:46 AM

Does anybody has ad-bs converter in javascript

Reply
Hiramani Pun2020-06-03 10:20 AM

today is 2020/06/03 and in nepali 2077/02/21, its showing nepali date 2077/2/20 , what's the problem ?

Reply
Sujan Stc2021-04-14 2:31 PM

Simple solution is above at my comment. Please check.

Pujan Niroula2020-06-03 1:06 PM

Set timezones to UTC. Place date_default_timezone_set('UTC'); before require("nepali-date.php");

Ankit Subedi2020-01-16 5:06 AM

First of all, thank you so much for the converter. But, I have a problem. The code works perfectly fine on localhost, but shows "Fatal error: Uncaught Error: Call to undefined function cal_days_in_month()" this error when deployed. Is there anything i am missing?

Reply
Pujan Niroula2020-01-17 4:54 PM

Sorry! I can't do anything for that. Looks like server side problem. :(

Yogendra2019-12-05 5:49 PM

I have been trying to use your code but it is returning the non numeric error and couldnot use it.could you please help out

Reply
Pujan Niroula2019-12-10 9:06 AM

I have updated the code. Please check, thanks :)

InNepall2019-11-06 4:14 AM

Can you please update the code. I am getting an error with PHP 7.3 "Warning: A non-numeric value encountered in ../nepali-date.php on line 190" Thank you for sharing your hard work.

Reply
Pujan Niroula2019-12-10 9:11 AM

I have updated the code, Please check thanks for your patience. :) Anyway there was little problem on 186 line. Compare to find out more :-D

Binod Stha2018-11-13 5:22 AM

Hi, Thanks for sharing. Please share your nepali date converter's full code also.

Reply
Baha2019-09-10 4:03 AM

https://github.com/bahadurbaniya/Date-Converter-Bikram-Sambat-to-English-Date full code in Java here.

Pujan Niroula2018-12-13 8:44 AM

Sorry for late reply... Currently we don't have plan to share these scripts, In future we will... Hope you understand...