We help IT Professionals succeed at work.

retrive the number of month from date field ....

dede11
dede11 asked
on
Medium Priority
285 Views
Last Modified: 2008-03-06
hi

I have a date field suppose (dateField) that I am attempting to use a query to determine the number of month....
for example, if the (dateField) is 30\4\1405 , I want to run a query that will return the  month (i.e. 4).  

thanks ....:)
Comment
Watch Question

Author

Commented:
note : the i am using hijri date ...
CERTIFIED EXPERT
Commented:
Hi dede11,
doesn't this work for hijri dates? (I don't know)
Month(datefield)

Pete

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Commented:
Does datepart("m",datefield) not work?
CERTIFIED EXPERT
Most Valuable Expert 2015
Distinguished Expert 2018

Commented:
As to this source:

http://www.islamicfinder.org/hijri_intro.php

this calender is not exact:

"Since the Islamic calendar is purely lunar, as apposed to solar or luni-solar,
the Muslim (Hijri) year is shorter than the Gregorian year by about 11 days .."

thus you'll have to run your own conversion routine, or convert it to the Gregorian calender where you can use the Month() function - but these months are different from yours ...

/gustav

Commented:
Hello,

If the date is stored as text in your database, you want to extract a portion of that string using the backslash delimiter. The following function can help:

Function HijriDatePart(pvarDate, pintPart As Integer)

On Error Resume Next

    HijriDatePart = Null
    HijriDatePart = CInt(Val(Split(pvarDate, "\")(pintPart)))

End Function

Place it in a module and you can then use it in a query, noting that the day is part 0, the month part 1 and the year part 2.

    HijriMonth: HijriDatePart( strTheDateField, 1 )

You can also do it all in a query expression, but it gets a little messy:

    HijriMonth: Val(Mid(Left([strField],InStr(InStr([strField],'\')+1,[strField],'\')),InStr([strField],'\')+1))

Hope this helps
(°v°)

Author

Commented:

Hello  experts ...
      thanks for response ...,

  Month(datefield).........and ........datepart("m",datefield) worked perfect with hijri date....:)

thanks again.. :)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.