Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

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

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 ....:)
0
dede11
Asked:
dede11
2 Solutions
 
dede11Author Commented:
note : the i am using hijri date ...
0
 
peter57rCommented:
Hi dede11,
doesn't this work for hijri dates? (I don't know)
Month(datefield)

Pete
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
sbiddleCommented:
Does datepart("m",datefield) not work?
0
 
Gustav BrockCIOCommented:
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
0
 
harfangCommented:
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°)
0
 
dede11Author Commented:

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

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

thanks again.. :)
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now