# Gregorian Date from Hijri

1. ## Gregorian Date from Hijri

the following function converts Gregorian Date to Hijri
But when I do the opposite it done work, I mean convert a Hijri date to
Gregorian.

Any Help?!!

Function DHijri(dtGegDate As Date) As String

' returns a date in Hijri format for a given western date
VBA.Calendar = vbCalHijri
DHijri = dtGegDate
VBA.Calendar = vbCalGreg

End Function

Thanks

Abdul

2. ## Re: Gregorian Date from Hijri

Abdul,
This seems to work

Public Function ChangeCalenderDate(InputDate As Date, _
ToHijri As Boolean, _
FormatStr As String) _
As String
Dim OldCalendar As VbCalendar
OldCalendar = Calendar

Calendar = -ToHijri
ChangeCalenderDate = Format(InputDate, FormatStr)
Calendar = OldCalendar

End Function

However according http://www.rabiah.com/convert/, this function gives a
result one day out, although the site does indicate this is possible, but
does not explain why.
If you real the Excel Help on this subject, you will see that you format
cells with either calendar.
As I never use any of this I can't help you as a lot of this depends on the
system/Excel version in use.

NickHK

"Abdul" <[email protected]>
???????:[email protected]...
> the following function converts Gregorian Date to Hijri
> But when I do the opposite it done work, I mean convert a Hijri date to
> Gregorian.
>
> Any Help?!!
>
>
>
> Function DHijri(dtGegDate As Date) As String
>
> ' returns a date in Hijri format for a given western date
> VBA.Calendar = vbCalHijri
> DHijri = dtGegDate
> VBA.Calendar = vbCalGreg
>
> End Function
>
> Thanks
>
> Abdul
>

3. ## Re: Gregorian Date from Hijri

thanks

How I could use this one as a formula in Excel

for eg.
In the function i posted if i type =DHijri(CellReference) it will
convert Gregorian to Hijri

now if I want to convert Hijri to Gregorian
=ChangeCalenderDate(CellReference) gives #Name! Error

Thanks

News wrote:
> Abdul,
> This seems to work
>
> Public Function ChangeCalenderDate(InputDate As Date, _
> ToHijri As Boolean, _
> FormatStr As String) _
> As String
> Dim OldCalendar As VbCalendar
> OldCalendar = Calendar
>
> Calendar = -ToHijri
> ChangeCalenderDate = Format(InputDate, FormatStr)
> Calendar = OldCalendar
>
> End Function
>
> However according http://www.rabiah.com/convert/, this function gives a
> result one day out, although the site does indicate this is possible, but
> does not explain why.
> If you real the Excel Help on this subject, you will see that you format
> cells with either calendar.
> As I never use any of this I can't help you as a lot of this depends on the
> system/Excel version in use.
>
> NickHK
>
> "Abdul" <[email protected]>
> ???????:[email protected]...
> > the following function converts Gregorian Date to Hijri
> > But when I do the opposite it done work, I mean convert a Hijri date to
> > Gregorian.
> >
> > Any Help?!!
> >
> >
> >
> > Function DHijri(dtGegDate As Date) As String
> >
> > ' returns a date in Hijri format for a given western date
> > VBA.Calendar = vbCalHijri
> > DHijri = dtGegDate
> > VBA.Calendar = vbCalGreg
> >
> > End Function
> >
> > Thanks
> >
> > Abdul
> >

4. ## Re: Gregorian Date from Hijri

You have to make a Public function in a module.
Also notice that there are 3 arguments that you need to supply, not just
one.

NickHK

"Abdul" <[email protected]>
???????:[email protected]...
> thanks
>
> How I could use this one as a formula in Excel
>
> for eg.
> In the function i posted if i type =DHijri(CellReference) it will
> convert Gregorian to Hijri
>
> now if I want to convert Hijri to Gregorian
> =ChangeCalenderDate(CellReference) gives #Name! Error
>
> Thanks
>
>
> News wrote:
>> Abdul,
>> This seems to work
>>
>> Public Function ChangeCalenderDate(InputDate As Date, _
>> ToHijri As Boolean, _
>> FormatStr As String) _
>> As String
>> Dim OldCalendar As VbCalendar
>> OldCalendar = Calendar
>>
>> Calendar = -ToHijri
>> ChangeCalenderDate = Format(InputDate, FormatStr)
>> Calendar = OldCalendar
>>
>> End Function
>>
>> However according http://www.rabiah.com/convert/, this function gives a
>> result one day out, although the site does indicate this is possible, but
>> does not explain why.
>> If you real the Excel Help on this subject, you will see that you format
>> cells with either calendar.
>> As I never use any of this I can't help you as a lot of this depends on
>> the
>> system/Excel version in use.
>>
>> NickHK
>>
>> "Abdul" <[email protected]>
>> ???????:[email protected]...
>> > the following function converts Gregorian Date to Hijri
>> > But when I do the opposite it done work, I mean convert a Hijri date to
>> > Gregorian.
>> >
>> > Any Help?!!
>> >
>> >
>> >
>> > Function DHijri(dtGegDate As Date) As String
>> >
>> > ' returns a date in Hijri format for a given western date
>> > VBA.Calendar = vbCalHijri
>> > DHijri = dtGegDate
>> > VBA.Calendar = vbCalGreg
>> >
>> > End Function
>> >
>> > Thanks
>> >
>> > Abdul
>> >

>

There are currently 1 users browsing this thread. (0 members and 1 guests)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1