+ Reply to Thread
Results 1 to 10 of 10

Dateserial equivalent for hijri dates

  1. #1
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Dateserial equivalent for hijri dates

    Hello everyone
    There is the function DateSerial that convert text to dates
    I have in range("C1") the text
    Please Login or Register  to view this content.
    And I used the following line of code to get the date
    Please Login or Register  to view this content.
    This is for Gregorian dates .. What about Hijrii dates?
    If I have this text in C1
    Please Login or Register  to view this content.
    I need to have the final result in D1 as follows
    26/10/1436
    and at the same time to be valid date not just a text

    Thanks advanced
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Dateserial equivalent for hijri dates

    ِAny idea about this topic?

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,437

    Re: Dateserial equivalent for hijri dates

    My first idea is that I know I have seen this question asked before. I do not know the answer myself, but it seems that I have seen formulas and udfs and such out there for converting dates between the Hijri and Gregorian calendars. I put "gregorian to hijri udf excel" into my favorite internet search engine and quickly found these pages that discuss the topic.
    https://support.microsoft.com/en-us/kb/871138 says that it only applies to Excel 2003, but mentions a registry edit that claims to allow Excel to recognize Gregorian and Hijri dates.
    http://download.cnet.com/Hijri-Grego...-75222365.html is for an add-in that claims to be able to convert between Gregorian and Hijri dates.
    http://www.access-programmers.co.uk/...d.php?t=246559 this forum thread presents code for Gregorian to Hijri and Hijri to Gregorian conversion UDFs.

    I have not tested any of these, nor am I familiar with the Islamic calendar so I cannot test them. See if any of those help.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Dateserial equivalent for hijri dates

    Thanks a lot sir
    but I don't need to convert between Gregorian and Hijri ..
    I need to convert text formed of 6 numbers like that
    Please Login or Register  to view this content.
    to Hijri date using UDF .. to have the final result
    Please Login or Register  to view this content.
    Thanks for help

  5. #5
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,437

    Re: Dateserial equivalent for hijri dates

    How closely did you look at the links I posted -- especially the third one? I was hoping that, even if the UDF's did not help you with your specific problem, there would be something in the code presented that would be applicable to your specific requirements. Looking at the code more closely, it appears that they are simply using the VBA.calendar property to perform the conversion. Here's the help file for the VBA.calendar property (https://msdn.microsoft.com/en-us/lib...=vs.60%29.aspx ) which has more code and UDF's. One of these UDF's appears to take a string input, selects the desired calendar using the vba.calendar property, then uses the CDate() function to convert the string input to a date in the desired calendar. It also takes and converts the date back to a string, but you may not need that step.

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Dateserial equivalent for hijri dates

    Thanks for this useful link
    I need to create date by splitting the 6 numbers to day / month / Add 14 + plus year
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Regardless the conversion process .. I don't need to convert Hijri to Gregorian ..

  7. #7
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,437

    Re: Dateserial equivalent for hijri dates

    Is there a specific part that you are having trouble with? It seems to me that it should be something like (untested pseudocode):

    Please Login or Register  to view this content.

  8. #8
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Dateserial equivalent for hijri dates

    Thank you very much for this great help
    Now I used this and it is OK
    Please Login or Register  to view this content.
    Is it necessary to include the VBA.Calendar type and reset it at the end ? What is the benefit of these procdures?

  9. #9
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,437

    Re: Dateserial equivalent for hijri dates

    As explained in the help file for the calendar property, the calendar property allows you to test and/or choose which calendar (Gregorian or Hijri) you want to use. Whether you need to include the VBA.calendar=1 at the beginning and/or VBA.calendar=0 at the end probably depends a lot on what this and other projects are doing.

    If, like me, you only use the default Gregorian calendar, you never need to use this or even be aware of it (I was not aware of the VBA.calendar property before this discussion. Everything I know about it is present in the links I have posted).

    If you only need the Hijri calendar, and never need the Gregorian, then you can perhaps have an auto open procedure of some kind that will set VBA.calendar to 1 and never worry about it.

    If you have some procedures that use the Hijri calendar and some that use the Gregorian calendar, it seems important to use the VBA.calendar property at the beginning and/or end of each procedure to test and/or set the desired calendar type so that the procedure will use the proper calendar, and leave the calendar setting at your desired default when the procedure ends.

    Are you certain that the above code is doing exactly what you asked for? When I execute, I get another text string back, not a date. Your stated goal at the beginning was to convert a text string that represents a date (in Hijri) into a date serial number, if I understood correctly. It does not appear to me that this procedure is doing that.

  10. #10
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Dateserial equivalent for hijri dates

    Thanks a lot for this useful illustration

    As for the function it works for me and I tested the result using IsDate function to make sure it is a date and it returns True
    Regards
    Last edited by YasserKhalil; 10-19-2015 at 10:02 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Get the last weeknum with DateSerial in Excel VBA
    By trizzo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-03-2015, 10:00 AM
  2. [SOLVED] Get the last date(last day) of the month with Excel VBA DateSerial
    By trizzo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-27-2015, 03:16 PM
  3. DateSerial and DateDiff macro won't work
    By TBC142 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-22-2015, 08:54 AM
  4. Question about dateserial
    By labogola in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-11-2014, 09:31 AM
  5. DateSerial
    By h_aesa1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-26-2010, 04:14 PM
  6. Remove Holidays as DateSerial using Case
    By David in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-19-2006, 10:05 PM
  7. Re: Time/DateSerial Numeric Value
    By Jay in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-16-2005, 12:06 AM

Bookmarks

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