If you are looking for code to put in your website visit http://nepalidateconve.sourceforge.net/ to download php code.
…..i don’t have time to read..download NepaliDateConverterAddIn.xlsm now.
The codes
Nepali date conversion consists of two parts
A. Data of number of days that occur in each month in each year. This is the reason why all the Nepali date conversion programs have its limitations
B. Algorithm to convert the date from AD to BS or vice versa.
This is explained with the code in VBA (in Excel) below with the required steps.
1. Open MS Excel
2. Open Visual Basic editor (short cut Alt + F11)
3. Insert a class module
4. Rename the class module to Nepali_Calender in Properties window (F4)
5. Paste the code 1 given at the end of this article
6. Insert a Module (normal module not class module!) and Paste the code 2 . It consists of two functions :
a. nepaliToEnglish(y,m,d,formateCode)
b. englishToNepali(y,m,d,formateCode)
where y,m,d=year, month and day and formate code will display the desired output format
Formate code |
Formate |
0 |
20671/25 |
1 |
2067-Mangsir-25 |
2 |
2067-Mangsir-25-Saturday |
7. Now close the editor
8. Save your file as *.xlsm (macro enabled)
9. Now you can use two functions made in step 6
10. To make these functions available to all the worksheets
a. save this sheet as add-ins *.xlam format
b. then enable it at Excel Options>Add in>Manage
c. the function will be available as user defined function under Insert functions
11. . In this code the limits are
a. AD 1944-2033
b. BS 2000-2089
c. if date is out of range then output is string “Out of range”
The readymade file is also available. Download NepaliDateConverterAddIn.xlsm now.
If you are looking for code to put in your website visit http://nepalidateconve.sourceforge.net/ to download php code.
Code1
Option Explicit
‘the original sorce code of this program is found in sourceforge.net
‘the code in php was translated to VBA
‘this add-in is copyfree and can be distributed freely in multiple copies
‘the user should be responsible for the use of this add in
‘the author is not liable for any damage that may occur by using this add-in
‘modification to the code is welcome. Any additional data in the code if notified over the internet will be usefull to all
‘***********************************************************************************************************
‘*******currently can only calculate the date between BS 2000-2089 and AD 1944-2033*************************
‘***********************************************************************************************************
‘Coder: Nirmal Raj Joshi
‘@copyfree nirmaljoshi.com.np,2010
‘joshi.amn@gmail.com
Private bs As Variant
Public nep_date As Dictionary
Public eng_date As Dictionary
Public debug_info
Sub initilizeClass()
ReDim bs(90)
bs(0) = Array(2000, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31)
bs(1) = Array(2001, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30)
bs(2) = Array(2002, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30)
bs(3) = Array(2003, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31)
bs(4) = Array(2004, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31)
bs(5) = Array(2005, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30)
bs(6) = Array(2006, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30)
bs(7) = Array(2007, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31)
bs(8) = Array(2008, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31)
bs(9) = Array(2009, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30)
bs(10) = Array(2010, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30)
bs(11) = Array(2011, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31)
bs(12) = Array(2012, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30)
bs(13) = Array(2013, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30)
bs(14) = Array(2014, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30)
bs(15) = Array(2015, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31)
bs(16) = Array(2016, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30)
bs(17) = Array(2017, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30)
bs(18) = Array(2018, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30)
bs(19) = Array(2019, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31)
bs(20) = Array(2020, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30)
bs(21) = Array(2021, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30)
bs(22) = Array(2022, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30)
bs(23) = Array(2023, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31)
bs(24) = Array(2024, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30)
bs(25) = Array(2025, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30)
bs(26) = Array(2026, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31)
bs(27) = Array(2027, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31)
bs(28) = Array(2028, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30)
bs(29) = Array(2029, 31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30)
bs(30) = Array(2030, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31)
bs(31) = Array(2031, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31)
bs(32) = Array(2032, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30)
bs(33) = Array(2033, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30)
bs(34) = Array(2034, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31)
bs(35) = Array(2035, 30, 32, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31)
bs(36) = Array(2036, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30)
bs(37) = Array(2037, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30)
bs(38) = Array(2038, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31)
bs(39) = Array(2039, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30)
bs(40) = Array(2040, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30)
bs(41) = Array(2041, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30)
bs(42) = Array(2042, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31)
bs(43) = Array(2043, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30)
bs(44) = Array(2044, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30)
bs(45) = Array(2045, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30)
bs(46) = Array(2046, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31)
bs(47) = Array(2047, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30)
bs(48) = Array(2048, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30)
bs(49) = Array(2049, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30)
bs(50) = Array(2050, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31)
bs(51) = Array(2051, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30)
bs(52) = Array(2052, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30)
bs(53) = Array(2053, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30)
bs(54) = Array(2054, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31)
bs(55) = Array(2055, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30)
bs(56) = Array(2056, 31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30)
bs(57) = Array(2057, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31)
bs(58) = Array(2058, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31)
bs(59) = Array(2059, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30)
bs(60) = Array(2060, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30)
bs(61) = Array(2061, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31)
bs(62) = Array(2062, 30, 32, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31)
bs(63) = Array(2063, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30)
bs(64) = Array(2064, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30)
bs(65) = Array(2065, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31)
bs(66) = Array(2066, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31)
bs(67) = Array(2067, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30)
bs(68) = Array(2068, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30)
bs(69) = Array(2069, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31)
bs(70) = Array(2070, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30)
bs(71) = Array(2071, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30)
bs(72) = Array(2072, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30)
bs(73) = Array(2073, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31)
bs(74) = Array(2074, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30)
bs(75) = Array(2075, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30)
bs(76) = Array(2076, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30)
bs(77) = Array(2077, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31)
bs(78) = Array(2078, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30)
bs(79) = Array(2079, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30)
bs(80) = Array(2080, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30)
bs(81) = Array(2081, 31, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30)
bs(82) = Array(2082, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30)
bs(83) = Array(2083, 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30)
bs(84) = Array(2084, 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30)
bs(85) = Array(2085, 31, 32, 31, 32, 30, 31, 30, 30, 29, 30, 30, 30)
bs(86) = Array(2086, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30)
bs(87) = Array(2087, 31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30)
bs(88) = Array(2088, 30, 31, 32, 32, 30, 31, 30, 30, 29, 30, 30, 30)
bs(89) = Array(2089, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30)
bs(90) = Array(2090, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30)
Set nep_date = New Dictionary
nep_date.Add “year”, 0
nep_date.Add “month”, 0
nep_date.Add “date”, 0
nep_date.Add “day”, 0
nep_date.Add “nmonth”, 0
nep_date.Add “num_day”, 0
Set eng_date = New Dictionary
eng_date.Add “year”, 0
eng_date.Add “month”, 0
eng_date.Add “date”, 0
eng_date.Add “day”, 0
eng_date.Add “emonth”, 0
eng_date.Add “num_day”, 0
End Sub
‘ /**
‘ * Calculates wheather english year is leap year or not
‘ *
‘ * @param integer $year
‘ * @return boolean
‘ */’
Public Function is_leap_year(year) As Boolean
Dim a, returnVal
a = year
If a Mod 100 = 0 Then
If a Mod 400 = 0 Then
returnVal = True
Else
returnVal = False
End If
Else
If a Mod 4 = 0 Then
returnVal = True
Else
returnVal = False
End If
End If
is_leap_year = returnVal
End Function
Public Function get_nepali_month(m)
Dim n_month
n_month = False
Select Case m
Case 1:
n_month = “Baishak”
Case 2:
n_month = “Jestha”
Case 3:
n_month = “Ashad”
Case 4:
n_month = “Shrawn”
Case 5:
n_month = “Bhadra”
Case 6:
n_month = “Ashwin”
Case 7:
n_month = “Kartik”
Case 8:
n_month = “Mangshir”
Case 9:
n_month = “Poush”
Case 10:
n_month = “Magh”
Case 11:
n_month = “Falgun”
Case 12:
n_month = “Chaitra”
End Select
get_nepali_month = n_month
End Function
Public Function get_english_month(m)
Dim eMonth
eMonth = False
Select Case m
Case 1
eMonth = “January”
Case 2:
eMonth = “February”
Case 3:
eMonth = “March”
Case 4:
eMonth = “April”
Case 5:
eMonth = “May”
Case 6:
eMonth = “June”
Case 7:
eMonth = “July”
Case 8:
eMonth = “August”
Case 9:
eMonth = “September”
Case 10:
eMonth = “October”
Case 11:
eMonth = “November”
Case 12:
eMonth = “December”
End Select
get_english_month = eMonth
End Function
Public Function get_day_of_week(d)
Dim day
day = False
Select Case d
Case 1:
day = “Sunday”
Case 2:
day = “Monday”
Case 3:
day = “Tuesday”
Case 4:
day = “Wednesday”
Case 5:
day = “Thursday”
Case 6:
day = “Friday”
Case 7:
day = “Saturday”
End Select
get_day_of_week = day
End Function
Public Function is_range_eng(yy, mm, dd)
Dim returnVal
returnVal = True
If (yy < 1944 Or yy > 2033) Then
debug_info = “Supported only between 1944-2022”
returnVal = False
End If
If (mm < 1 Or mm > 12) Then
debug_info = “Error! value 1-12 only”
returnVal = False
End If
If (dd < 1 Or dd > 31) Then
debug_info = “Error! value 1-31 only”
returnVal = False
End If
is_range_eng = returnVal
End Function
Public Function is_range_nep(yy, mm, dd)
Dim returnVal
returnVal = True
If (yy < 2000 Or yy > 2089) Then
debug_info = “Supported only between 2000-2089”
returnVal = False
End If
If (mm < 1 Or mm > 12) Then
debug_info = “Error! value 1-12 only”
returnVal = False
End If
If (dd < 1 Or dd > 32) Then
debug_info = “Error! value 1-31 only”
returnVal = False
End If
is_range_nep = returnVal
End Function
‘ /**
‘ * currently can only calculate the date between AD 1944-2033…
‘ *
‘ * @param unknown_type $yy
‘ * @param unknown_type $mm
‘ * @param unknown_type $dd
‘ * @return unknown
‘ */
Public Sub eng_to_nep(yy, mm, dd)
If (is_range_eng(yy, mm, dd) = False) Then
debug_info = “Out of range”
Else
‘ // english month data.
Dim month, lmonth
month = Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
lmonth = Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
Dim def_eyy, def_nyy, def_nmm, def_ndd
Dim total_eDays, total_nDays, a, day
Dim m, y, i, j
Dim numDay
def_eyy = 1944 ‘ //spear head english date…
def_nyy = 2000: def_nmm = 9: def_ndd = 17 – 1 ‘ //spear head nepali date…
total_eDays = 0: total_nDays = 0: a = 0: day = 7 – 1 ‘ //all the initializations…
m = 0: y = 0: i = 0: j = 0
numDay = 0
‘// count total no. of days in-terms of year
For i = 0 To yy – def_eyy – 1 ‘ //total days for month calculation…(english)
If (is_leap_year(def_eyy + i) = True) Then
For j = 0 To 12 – 1
total_eDays = total_eDays + lmonth(j)
Next j
Else
For j = 0 To 12 – 1
total_eDays = total_eDays + month(j)
Next j
End If
Next i
‘// count total no. of days in-terms of month
For i = 0 To (mm – 1) – 1
If (is_leap_year(yy) = True) Then
total_eDays = total_eDays + lmonth(i)
Else
total_eDays = total_eDays + month(i)
End If
Next i
‘ // count total no. of days in-terms of date
total_eDays = total_eDays + dd
i = 0: j = def_nmm
total_nDays = def_ndd
m = def_nmm
y = def_nyy
‘// count nepali date from array
Do While (total_eDays <> 0)
a = bs(i)(j)
total_nDays = total_nDays + 1 ‘ //count the days
day = day + 1 ‘ //count the days interms of 7 days
If (total_nDays > a) Then
m = m + 1
total_nDays = 1
j = j + 1
End If
If (day > 7) Then
day = 1
End If
If (m > 12) Then
y = y + 1
m = 1
End If
If (j > 12) Then
j = 1: i = i + 1
End If
total_eDays = total_eDays – 1
Loop
numDay = day
nep_date(“year”) = y
nep_date(“month”) = m
nep_date(“date”) = total_nDays
nep_date(“day”) = get_day_of_week(day)
nep_date(“nmonth”) = get_nepali_month(m)
nep_date(“num_day”) = numDay
End If
End Sub
‘
‘ /**
‘ * currently can only calculate the date between BS 2000-2089
‘ *
‘ * @param unknown_type $yy
‘ * @param unknown_type $mm
‘ * @param unknown_type $dd
‘ * @return unknown
‘ */
Public Sub nep_to_eng(yy, mm, dd)
Dim def_eyy, def_emm, def_edd
Dim def_nyy, def_nmm, def_ndd
Dim total_eDays, total_nDays, a, day
Dim m, y, i, j
Dim k, numDay
Dim month, lmonth
def_eyy = 1943: def_emm = 4: def_edd = 14 – 1 ‘// init english date.
def_nyy = 2000: def_nmm = 1: def_ndd = 1 ‘ // equivalent nepali date.
total_eDays = 0: total_nDays = 0: a = 0: day = 4 – 1 ‘ // initializations…
m = 0: y = 0: i = 0
k = 0: numDay = 0
month = Array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
lmonth = Array(0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
If (is_range_nep(yy, mm, dd) = False) Then
debug_info = “Out of range”
Else
‘// count total days in-terms of year
For i = 0 To yy – def_nyy – 1
For j = 1 To 12
total_nDays = total_nDays + bs(k)(j)
Next j
k = k + 1
Next i
‘// count total days in-terms of month
For j = 1 To mm – 1
total_nDays = total_nDays + bs(k)(j)
Next j
‘// count total days in-terms of dat
total_nDays = total_nDays + dd
‘//calculation of equivalent english date…
total_eDays = def_edd
m = def_emm
y = def_eyy
Do While (total_nDays <> 0)
If (is_leap_year(y)) Then
a = lmonth(m)
Else
a = month(m)
End If
total_eDays = total_eDays + 1
day = day + 1
If (total_eDays > a) Then
m = m + 1
total_eDays = 1
If (m > 12) Then
y = y + 1
m = 1
End If
End If
If (day > 7) Then day = 1
total_nDays = total_nDays – 1
Loop
numDay = day
eng_date(“year”) = y
eng_date(“month”) = m
eng_date(“date”) = total_eDays
eng_date(“day”) = get_day_of_week(day)
eng_date(“emonth”) = get_english_month(m)
eng_date(“num_day”) = numDay
End If
End Sub
Code 2
Public Function nepaliToEnglish(yy, mm, dd, formate)
‘ this function depends on Nepali_calander class
‘@copyfree nirmaljoshi.com.np,2010
‘formateType default=2010/1/25
‘formateType 1=2010-jan-25
‘formateType 2=2010-jan-25-saturday
If IsMissing(formate) Then formateType = 0
‘MsgBox formateType
Dim a As Nepali_Calender
Set a = New Nepali_Calender
Call a.initilizeClass
Call a.nep_to_eng(yy, mm, dd)
If a.debug_info = “” Then
Select Case formate
Case 1:
output = a.eng_date(“year”) & “-” & a.eng_date(“emonth”) & “-” & a.eng_date(“date”)
Case 2:
output = a.eng_date(“year”) & “-” & a.eng_date(“emonth”) & “-” & a.eng_date(“date”) & “-” & a.eng_date(“day”)
Case Else:
output = a.eng_date(“year”) & “/” & a.eng_date(“month”) & “/” & a.eng_date(“date”)
End Select
Else
output = a.debug_info
End If
nepaliToEnglish = output
End Function
Public Function englishToNepali(yy, mm, dd, formate)
‘ this function depends on Nepali_calander class
‘@copyfree nirmaljoshi.com.np,2010
‘formateType default=20671/25
‘formateType 1=2067-mangsir-25
‘formateType 2=2067-mangsir-25-saturday
If IsMissing(formate) Then formateType = 0
‘MsgBox formateType
Dim a As Nepali_Calender
Set a = New Nepali_Calender
Call a.initilizeClass
Call a.eng_to_nep(yy, mm, dd)
If a.debug_info = “” Then
Select Case formate
Case 1:
output = a.nep_date(“year”) & “-” & a.nep_date(“nmonth”) & “-” & a.nep_date(“date”)
Case 2:
output = a.nep_date(“year”) & “-” & a.nep_date(“nmonth”) & “-” & a.nep_date(“date”) & “-” & a.nep_date(“day”)
Case Else:
output = a.nep_date(“year”) & “/” & a.nep_date(“month”) & “/” & a.nep_date(“date”)
End Select
Else
output = a.debug_info
End If
englishToNepali = output
End Function
Comments
Nice work there. I’ve been looking for something like this for a long time. Quite an effort you’ve put there.
Kudos to you my friend.
Binay
thanks man..
can we use this code in ms access or sql?if yes how? hope you will help me? thanx in adv.
Yes, this can be done.The syntax of the doing this depends upon the type of programming language you’ll use like ‘php’ or ‘vb’ or ‘c’ etc. I hope you will learn yourself to implement this as per your requirements. If you require further assistance please put a message.
thank you for ur reply
welcome!
I tried this code, it works well in excel but when i tried this code in vb 6.0 an error occured saying “User defined type not defined” for the code:
Public nep_date As Dictionary
Public eng_date As Dictionary
Is there any way to resolve this problem? I tried a lot but cant solve this problem.
The dictinary class of VBA of excel is similar to associative array. I am not sure if VB-6 has this feature or not. But other language like php and java etc has this feature. In the associative array we can recall the value by using the key. The key is string and is similar to index of an array. Following example will illustrate it. And by the way you can use just a siple array as well.
Associatve array:
A("Key")=value
If there is no feature of this then you can use
A(1)=value
and just follow the index to take out our value.
The code in excel is
Set eng_date = New Dictionary
eng_date.Add "year", 0
eng_date.Add "month", 0
eng_date.Add "date", 0
eng_date.Add "day", 0
eng_date.Add "emonth", 0
eng_date.Add "num_day", 0
it should look like following if there is associative array.
dim eng_date(4)
eng_date("year")= 0
eng_date("month")= 0
eng_date("date")= 0
eng_date("day")= 0
eng_date("emonth")= 0
eng_date("num_day")= 0
Or just use
dim eng_date(4)
eng_date(0)= 0
eng_date(1)= 0
eng_date(2)= 0
eng_date(3)= 0
eng_date(4)= 0
eng_date(5)= 0
where 0=year,1=month etc..
in excel there is no such delaration possible hence we had to use DICTIONARY class.
Hope this will help you.
Cheers!
thanx man… i was having problem in getting the total days difference between ad and bs…. bt studing ur algorithm i got the logic…. thanx again….
Nice post…It was really helpful
thank you.
Thanks Man, Sounds great… i get the logic and will try to create API… hope it will work.
Hi Nirmal Ji
I followed exactly same as you said I typed following in excel cell.
=englishToNepali(2011,6,6,0)
but it displays error message
————-
Compile Error
User defined-type not defined
————-
error is displaying in the line
Public nep_date As Dictionary
in Nepali_Calender Class module
Could you please write me back.
thank you.
SKC
Hi, SKC,
Probably you didnt enable the macros in the excel sheet. Or more likely, you copied and pasted the macros in normal “module” only but forgot to copy the macro in “class module”.
You try the excel sheet as linked in the same page. URL to download the file is:
http://www.fileden.com/files/2010/9/12/2967753/SharingKnowledgeBlog/NepaliDateConverterAddIn.xlsm
Please see the macros in this file. If u have further queries tell me.
Thanks for your effort. This is exactly what I’ve been looking for. 🙂
how can we use this code in ms access or sql?
Thanks for the code. I was looking for it.
could you post an algorithm or at least a formula for the conversion. I am not good at either of the above languages. Or it will be much better if you posted a python version of functions eng_to_nep() and nep_to_eng() if you know python.
i know only one python.. and this reptile is very poisionous… hope you will crack the codes yourself.
I’m half way there. And yes, pythons are not poisonous. Its a helpful post by the way 😀
Thanx a lot…
nice work
can anyone provide php version
http://nepalidateconve.sourceforge.net/
Can I get a C code for this program?
can i get vb.net code
sir I want this code on vb6.or I want ocx activeX control for convert AD to BS.please help me
This works in Excel Vba – however Access Vba does not support Dictionaries :(.
I will have to rewrite for Access.
Nicely self-annotated code :).
Anyone have the code for Access?
a day and a half + some thinking and it works in VBa for Access. Nice work and Thanks
Thank you for the code. I want to get Month or Day only like englishToNepali(MONTH(TODAY())) OR englishToNepali(DAY(TODAY()))
thanks for code, but can some one provide me code for VBA Access plz, a am unble to convert
Dear Nirloj sir,
i tried in excel for nepali to english date convert it’s work for one only i need 2 or more cell convert in one click is it possible or not? if possible can you please teach me about formula for my problem. i have to changed 1000 and more cell with one formula.
please help me…….!!!!
Can we use this to change the date to bs in the post date in wordpress??
If there is compile time error saying ‘user type not defined’, in VBA editor goto Tools>Reference and check Microsoft Scripting Runtime.
problem not solved. please can someone provide the excel file
Please download the excel file and see the codes. I have updated the link to file which was dead due to shift in google drive.
Hi Nirmal Sir. I have tried the code but it shows value error. I had put code 1 in class module and code 2 in normal module. Please help me for the solution of problem
Please download the excel file and see the codes. I have updated the link to file which was dead due to shift in google drive.
i was hoping for an real algo, this info can be easily collected thru many medias.
I was exactly looking for the same code. But when I checked it, there was bugs.
10/30/2073 2017-February-12-Sunday
9/30/2073 2017-January-14-Saturday
8/30/2073 2016-December-15-Thursday
7/30/2073 2016-November-15-Tuesday
The first two rows should have given errors. Instead it returned outputs like this.
There are bugs. It shouldn’t have converted 2073/10/30 & 2073/9/30. But it does. Please check
what is the issue? I think its working fine.
There are no dates 2073/10/30 and 9/30 but it is showing it as 2/12 and 1/14
Yes you are correct. The input should be checked before entering. GIGO… 😛
9/29/2073 2017-January-13-Friday
9/30/2073 2017-January-14-Saturday
There is no 9/30
Can you put some validation in your code so that it checks in the case statement if that particular month has no more days than prescribed.
good suggestion. Will update in next version. Thanks.
I’m hoping that you update it at the earliest. I have been using your add-ins and now stuck there.