Results 1 to 8 of 8
  1. #1
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Jerusalem, Israel
    Posts
    708
    Thanks
    0
    Thanked 1 Time in 1 Post

    Create VBA from API of Calendar (xp)

    I found the code below, that to my limited knowledge is utilizing the windows API to access other calendars in the system to convert a date to and from Civil to Hebrew. I know absolutely nothing about API calls. IF I am correct is there a way to use this in a VBA function (specifically for Access) to extract the other calendar date given the civil date. I think the important part is where it starts :

    CultureInfo jewishCulture = CultureInfo.CreateSpecificCulture("he-IL");
    System.Globalization.HebrewCalendar cal =
    new System.Globalization.HebrewCalendar();
    jewishCulture.DateTimeFormat.Calendar = cal;

    Much Thanks to anyone who can help

    supply a default
    public static DateTime GetIsraelTime() {
    return (GetIsraelTime(DateTime.UtcNow));
    }

    // input: UTC DateTime object
    public static DateTime GetIsraelTime(DateTime d) {
    d = d.AddHours(2); // Israel is at GMT+2

    // April 2nd, 2:00 AM
    DateTime DSTStart = new DateTime(d.Year, 4, 2, 2, 0 ,0);
    while (DSTStart.DayOfWeek != DayOfWeek.Friday)
    DSTStart = DSTStart.AddDays(-1);

    CultureInfo jewishCulture = CultureInfo.CreateSpecificCulture("he-IL");
    System.Globalization.HebrewCalendar cal =
    new System.Globalization.HebrewCalendar();
    jewishCulture.DateTimeFormat.Calendar = cal;
    // Yom HaKipurim, at the start of the next Jewish year, 2:00 AM
    DateTime DSTFinish =
    new DateTime(cal.GetYear(DSTStart)+1, 1, 10, 2, 0 ,0, cal);
    while (DSTFinish.DayOfWeek != DayOfWeek.Sunday)
    DSTFinish= DSTFinish.AddDays(-1);

    if (d>DSTStart && d<DSTFinish)
    d = d.AddHours(1);

    return (d);

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Create VBA from API of Calendar (xp)

    The code you post (JavaScript?) is far from complete. Terms like CultureInfo, Globalization etc. aren't defined . So without further information it is impossible to do anything with it in VBA.

  3. #3
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Create VBA from API of Calendar (xp)

    This code is not an API call, but relates to to the .NET Framework Class Library

    See this MSDN article

    Andrew C

  4. #4
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Jerusalem, Israel
    Posts
    708
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Create VBA from API of Calendar (xp)

    thanks for everyone's responses. I think using this to convert from one calendar to another is way beyond me

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Create VBA from API of Calendar (xp)

    You can find VBA code to convert dates from the Gregorian calendar to the Hebrew calendar and back at Code of Varying Usefulness - Trigeminal Software, Inc. (English). Download the HebrewAndGregorian.bas code module and import it into your database/spreadsheet/document in the Visual Basic Editor.

    You can use it like this:

    Dim dtDate As Date
    dtDate = GregorianDateOfHebrewDate(5765, 11, 15)

    and

    Dim dtDate As Date
    Dim y As Long, m As Long, d As Long
    dtDate = #07/22/2005#
    HebrewDateOfGregorianDate dtDate, y, m, d
    Debug.Print y, m, d

  6. #6
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Jerusalem, Israel
    Posts
    708
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Create VBA from API of Calendar (xp)

    Thanks Hans. I am using that, but there seems to be some bug in the calculation since some dates are off by 1. I would love to use whatever Windows uses , since we all know that MSFT is perfect! <img src=/S/bananas.gif border=0 alt=bananas width=33 height=35>

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Create VBA from API of Calendar (xp)

    I'm afraid I have no idea how the code I posted a link to works, so I cannot offer suggestions for correcting it.

  8. #8
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Jerusalem, Israel
    Posts
    708
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Create VBA from API of Calendar (xp)

    Even though I have a general idea, it is very complicated, and the odds of my figuring out the bug are minimal. I am looking into a commercial product called KAluachDll that seems to work. As usual thanks for all your help

Posting Permissions

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