=Format(Now();"yyyy")

  • Thread starter Thread starter 1aae
  • Start date Start date
1

1aae

International Question:
=Format(Now();"yyyy")
previous code display code current year like 2004 ( can any one tell me)
how to change code to Hijri Date like 1425
What Is The Function need to convert to Hijri date
Thank you
 
1aae said:
International Question:
=Format(Now();"yyyy")
previous code display code current year like 2004 ( can any one tell
me) how to change code to Hijri Date like 1425
What Is The Function need to convert to Hijri date
Thank you

You can set the Hijri Calendar option for your database as a whole from
the International tab of the Tools -> Options... dialog. If you want to
do a quick conversion of a date value to the Hijri calendar, it's
another matter. I don't know anything about internationalization, and I
don't know if this has any bad side effects, but from my reading it
seems you could do something like this:

'----- start of untested function -----
Function HijriFormat( _
FormatString As String, _
Optional GivenDate As Date = Date()) _
As String

On Error GoTo Err_Handler

Calendar = vbCalHijri
HijriFormat = Format(GivenDate, FormatString)

Exit_Point:
Calendar = vbCalGreg
Exit Function

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_Point

End Function
'----- end of function -----

Then you would call it like this:

=HijriFormat("yyyy")

or

strHijriDate = HijriFormat("mm/dd/yyyy", [DateField])
 
Dirk Goldgar said:
1aae said:
International Question:
=Format(Now();"yyyy")
previous code display code current year like 2004 ( can any one tell
me) how to change code to Hijri Date like 1425
What Is The Function need to convert to Hijri date
Thank you

You can set the Hijri Calendar option for your database as a whole
from the International tab of the Tools -> Options... dialog. If you
want to do a quick conversion of a date value to the Hijri calendar,
it's another matter. I don't know anything about
internationalization, and I don't know if this has any bad side
effects, but from my reading it seems you could do something like
this:

'----- start of untested function -----
Function HijriFormat( _
FormatString As String, _
Optional GivenDate As Date = Date()) _
As String

On Error GoTo Err_Handler

Calendar = vbCalHijri
HijriFormat = Format(GivenDate, FormatString)

Exit_Point:
Calendar = vbCalGreg
Exit Function

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_Point

End Function
'----- end of function -----

Then you would call it like this:

=HijriFormat("yyyy")

or

strHijriDate = HijriFormat("mm/dd/yyyy", [DateField])

I just noticed that your list separator is the semicolon, not the comma.
You'd need to change the above code accordingly.
 
after copying and the function in form module this error appear:
---
Compile error:
Constant expression required:

and pervent me from put ( ) beside date ( ) and this function will be like
this:
Function HijriFormat(FormatString As String, Optional GivenDate As Date
=>>>>> Date<<<<<) As String


Dirk Goldgar said:
1aae said:
International Question:
=Format(Now();"yyyy")
previous code display code current year like 2004 ( can any one tell
me) how to change code to Hijri Date like 1425
What Is The Function need to convert to Hijri date
Thank you

You can set the Hijri Calendar option for your database as a whole from
the International tab of the Tools -> Options... dialog. If you want to
do a quick conversion of a date value to the Hijri calendar, it's
another matter. I don't know anything about internationalization, and I
don't know if this has any bad side effects, but from my reading it
seems you could do something like this:

'----- start of untested function -----
Function HijriFormat( _
FormatString As String, _
Optional GivenDate As Date = Date()) _
As String

On Error GoTo Err_Handler

Calendar = vbCalHijri
HijriFormat = Format(GivenDate, FormatString)

Exit_Point:
Calendar = vbCalGreg
Exit Function

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_Point

End Function
'----- end of function -----

Then you would call it like this:

=HijriFormat("yyyy")

or

strHijriDate = HijriFormat("mm/dd/yyyy", [DateField])

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
1aae said:
after copying and the function in form module this error appear:
---
Compile error:
Constant expression required:

and pervent me from put ( ) beside date ( ) and this function will be
like this:
Function HijriFormat(FormatString As String, Optional GivenDate As
Date =>>>>> Date<<<<<) As String

Oops! I warned you it was untested. Try this version:

'----- start of revised code -----
Function HijriFormat( _
FormatString As String, _
Optional ByVal GivenDate As Variant) _
As String


On Error GoTo Err_Handler

If IsMissing(GivenDate) Then
GivenDate = Date
End If

Calendar = vbCalHijri
HijriFormat = Format(GivenDate, FormatString)

Exit_Point:
Calendar = vbCalGreg
Exit Function

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_Point

End Function
'----- end of revised code -----
 
1aae said:
How can I use this function with text box to display Hijri format:
Thank you

If you just want to display the current Hijri year, use this expression
as the ControlSource of a text box:

=HijriFormat("yyyy")
 
MVP DriKGoldgar
Thank you very much for your help and answer
I want to you best live and Best health and Best Friend and Best Family
 
Back
Top