Results 1 to 6 of 6

Thread: Offset Internal Calendar by Plus/Minus 2 Days???

  1. #1

    Thread Starter
    Hyperactive Member Hassan Basri's Avatar
    Join Date
    Sep 2006
    Posts
    324

    Exclamation Offset Internal Calendar by Plus/Minus 2 Days???

    I have an application that converts dates between the two calendars in VB like this:

    VB Code:
    1. Dim dt as Date
    2.  
    3. dt = Date
    4.  
    5. Calendar = vbCalGreg
    6.  
    7. Msgbox dt
    8.  
    9. Calendar = vbCalHijri
    10.  
    11. Msgbox dt

    This works fine, however the hijri calendar is not fixed like the gregorian calendar depending on moon sightings.

    What I would like to do is find a way to offset the result returned by windows for the hijri calendar through either api calls or a setting in the registry.

    Using Dateadd function is not a solution as the application uses the results in constructing a calendar. The solution must involve either api call or setting in the registry.

    Any help would be appreciated. Thank you in advance.

  2. #2

    Thread Starter
    Hyperactive Member Hassan Basri's Avatar
    Join Date
    Sep 2006
    Posts
    324

    Re: Offset Internal Calendar by Plus/Minus 2 Days???

    Ok I found this on MSDN, however when I change the registry value it doesn't change anything. I tried rebooting and it still is not working.

    http://www.microsoft.com/middleeast/...cCalendar.aspx
    =============================
    You can adjust the Hijri Calendar from your registry, by modifying the AddHijriDate key value at

    HKEY_CURRENT_USER\Control Panel\International\ and setting it to one of the following values:

    Value


    Meaning

    AddHijriDate-2 Subtract two days.
    AddHijriDate Subtract one day.

    (blank) No adjustment is necessary. (If the date has not been adjusted, this entry does not appear in the registry. If the date has been adjusted and then restored to its original value, this entry appears in the registry with no value.)

    AddHijriDate+1 Add one day.
    AddHijriDate+2 Add two days.

  3. #3

    Thread Starter
    Hyperactive Member Hassan Basri's Avatar
    Join Date
    Sep 2006
    Posts
    324

    Re: Offset Internal Calendar by Plus/Minus 2 Days???

    I still have not found a solution for this problem, so I will rephrase the question. Let us say I want the Date function of VB to return a date that is plus/minus the date but the same weekday.

    For example today is Friday November 3rd 2006

    I want the function to return Friday November 1st 2006.

    The reason is that I build a picturebox calendar with the dates but for the Hijri calendar can be offset plus/minus 2 days.

    Any ideas? Thank you for any assistance.

  4. #4
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Offset Internal Calendar by Plus/Minus 2 Days???

    You can add or remove two days with the DateAdd() function:
    VB Code:
    1. Debug.Print DateAdd("d", 2, dt)
    2. Debug.Print DateAdd("d", -2, dt)
    But to be the same weekday... I can't see how's that possible

  5. #5

    Thread Starter
    Hyperactive Member Hassan Basri's Avatar
    Join Date
    Sep 2006
    Posts
    324

    Re: Offset Internal Calendar by Plus/Minus 2 Days???

    Thank you gavio but using Dateadd function is not a solution as the application uses the results in constructing the picturebox calendar. The solution must involve either an api call or setting in the registry. Unless there is another solution?

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Offset Internal Calendar by Plus/Minus 2 Days???

    date will ruturn the current system date so this will return what you ask for

    VB Code:
    1. x = -2
    2. mydate = Format(Date, "dddd ") & Format(DateAdd("d", x, Date), "dd") & Format(Date, "/mm/yyyy")
    3. Debug.Print mydate    ' Saturday 02/11/2006

    Edit:
    you can also try this to see if it gives any useful result
    VB Code:
    1. VBA.Calendar = vbCalHijri
    2. Debug.Print Now
    3. VBA.Calendar = vbCalGreg
    4. Debug.Print Now
    Last edited by westconn1; Nov 3rd, 2006 at 11:52 PM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width